@bleedingdev/modern-js-server-runtime-extensions 3.9.0-ultramodern.4 → 3.9.0-ultramodern.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bff-policy/crossProjectPolicy.js +309 -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/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/canaryCompatibility.js +73 -0
- package/dist/cjs/telemetry/healthSetup.js +4 -0
- package/dist/cjs/telemetry/lifecycle.js +15 -16
- package/dist/cjs/telemetry/plugin.js +10 -3
- package/dist/cjs/telemetry/runtimeEndpoints.js +10 -3
- package/dist/esm/bff-policy/crossProjectPolicy.mjs +259 -0
- package/dist/esm/bff-policy/index.mjs +1 -0
- 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/canaryCompatibility.mjs +35 -0
- package/dist/esm/telemetry/healthSetup.mjs +4 -0
- package/dist/esm/telemetry/lifecycle.mjs +15 -16
- package/dist/esm/telemetry/plugin.mjs +9 -2
- package/dist/esm/telemetry/runtimeEndpoints.mjs +10 -3
- package/dist/esm-node/bff-policy/crossProjectPolicy.mjs +260 -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/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/canaryCompatibility.mjs +36 -0
- package/dist/esm-node/telemetry/healthSetup.mjs +4 -0
- package/dist/esm-node/telemetry/lifecycle.mjs +15 -16
- package/dist/esm-node/telemetry/plugin.mjs +9 -2
- package/dist/esm-node/telemetry/runtimeEndpoints.mjs +10 -3
- package/dist/types/bff-policy/crossProjectPolicy.d.ts +110 -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/errorResponsePlugin.d.ts +3 -0
- package/dist/types/index.d.ts +1 -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/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/canaryCompatibility.d.ts +19 -0
- package/dist/types/telemetry/healthSetup.d.ts +3 -1
- package/dist/types/telemetry/lifecycle.d.ts +2 -2
- package/dist/types/telemetry/plugin.d.ts +2 -1
- package/dist/types/telemetry/runtimeEndpoints.d.ts +3 -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 +110 -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/canaryCompatibility.d.mts +19 -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 +19 -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 +37 -0
- package/dist/types-esm/telemetry.d.mts +1 -0
- package/dist/types-esm/telemetryCore.d.mts +6 -0
- package/package.json +158 -26
- package/rslib.config.mts +36 -2
- package/rstest.config.mts +11 -0
- package/src/bff-policy/crossProjectPolicy.ts +781 -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/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/canaryCompatibility.ts +55 -0
- package/src/telemetry/healthSetup.ts +9 -1
- package/src/telemetry/lifecycle.ts +20 -32
- package/src/telemetry/plugin.ts +6 -2
- package/src/telemetry/runtimeEndpoints.ts +13 -2
- package/tests/bff-policy/crossProjectPolicy.matrix.test.ts +487 -0
- package/tests/bff-policy/crossProjectPolicy.test.ts +1004 -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 +134 -0
- package/tests/contractGateSnapshotObserver.test.ts +0 -58
- 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 +199 -0
- package/tests/nativeServerAssembly.test.ts +402 -0
- package/tests/registration.test.ts +1 -86
- package/tests/runtimeLifecycle.test.ts +69 -17
- package/tests/static-serving/ordering.test.ts +214 -0
- package/tests/static-serving/provider.test.ts +83 -0
- package/tests/static-serving/static.test.ts +400 -0
- package/tests/telemetry.test.ts +35 -101
- package/tests/telemetryAutopilot.test.ts +5 -146
- package/tests/telemetryCanaryCompatibility.test.ts +152 -0
- package/tests/telemetryHealthMonitor.test.ts +0 -2
- package/tests/telemetryLifecycle.test.ts +11 -253
- package/tests/telemetryRegistryQueueMatrix.test.ts +0 -1
|
@@ -0,0 +1,309 @@
|
|
|
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
|
+
let hasWarnedAdvisoryNamespaceAllowlist = false;
|
|
36
|
+
const splitRoutePath = (routePath)=>routePath.split('/').filter(Boolean);
|
|
37
|
+
const isDynamicRouteSegment = (segment)=>segment.startsWith(':') || '*' === segment || segment.startsWith('*') || segment.startsWith('{*');
|
|
38
|
+
const hasTrailingSlash = (routePath)=>routePath.length > 1 && routePath.endsWith('/');
|
|
39
|
+
const hasUnsafePathEncoding = (requestPath)=>{
|
|
40
|
+
let decoded = requestPath;
|
|
41
|
+
for(let depth = 0; depth < 8; depth += 1){
|
|
42
|
+
if (/%(?:2f|5c)/i.test(decoded)) return true;
|
|
43
|
+
try {
|
|
44
|
+
const next = decodeURIComponent(decoded);
|
|
45
|
+
if (next === decoded) return false;
|
|
46
|
+
decoded = next;
|
|
47
|
+
} catch {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return decoded.includes('%');
|
|
52
|
+
};
|
|
53
|
+
const routeSegmentsMatch = (templateSegments, requestSegments)=>{
|
|
54
|
+
let templateIndex = 0;
|
|
55
|
+
let requestIndex = 0;
|
|
56
|
+
while(templateIndex < templateSegments.length){
|
|
57
|
+
const segment = templateSegments[templateIndex];
|
|
58
|
+
const wildcard = '*' === segment || segment.startsWith('*') || segment.startsWith('{*');
|
|
59
|
+
const optional = segment.startsWith(':') && segment.endsWith('?');
|
|
60
|
+
if (templateIndex < templateSegments.length - 1 && (wildcard || optional)) return false;
|
|
61
|
+
if (wildcard) return true;
|
|
62
|
+
const requestSegment = requestSegments[requestIndex];
|
|
63
|
+
if (void 0 === requestSegment) return optional && templateIndex === templateSegments.length - 1;
|
|
64
|
+
if (!segment.startsWith(':') && segment !== requestSegment) return false;
|
|
65
|
+
templateIndex += 1;
|
|
66
|
+
requestIndex += 1;
|
|
67
|
+
}
|
|
68
|
+
return requestIndex === requestSegments.length;
|
|
69
|
+
};
|
|
70
|
+
const routeTemplateMatchScore = (routePath, requestPath)=>{
|
|
71
|
+
if (hasTrailingSlash(routePath) !== hasTrailingSlash(requestPath)) return;
|
|
72
|
+
const templateSegments = splitRoutePath(routePath);
|
|
73
|
+
const requestSegments = splitRoutePath(requestPath);
|
|
74
|
+
for(let prefixLength = 0; prefixLength <= templateSegments.length; prefixLength += 1){
|
|
75
|
+
const removedPrefix = templateSegments.slice(0, prefixLength);
|
|
76
|
+
if (removedPrefix.some(isDynamicRouteSegment)) break;
|
|
77
|
+
const mountedTemplate = templateSegments.slice(prefixLength);
|
|
78
|
+
if (!routeSegmentsMatch(mountedTemplate, requestSegments)) continue;
|
|
79
|
+
const literalSegments = mountedTemplate.filter((segment)=>!isDynamicRouteSegment(segment)).length;
|
|
80
|
+
const dynamicSegments = mountedTemplate.length - literalSegments;
|
|
81
|
+
return (0 === prefixLength ? 1000000 : 0) + 10000 * literalSegments - 100 * dynamicSegments - prefixLength;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const resolveCrossProjectRequestObservation = (request, policy)=>{
|
|
85
|
+
const requestMethod = String(request.method || '').trim().toUpperCase();
|
|
86
|
+
const routePaths = [
|
|
87
|
+
...new Set(Object.keys(policy.expectedOperationContracts ?? {}).flatMap((key)=>{
|
|
88
|
+
if (key.startsWith('operation:')) return [];
|
|
89
|
+
const separator = key.indexOf(':');
|
|
90
|
+
if (-1 === separator || key.slice(0, separator).trim().toUpperCase() !== requestMethod) return [];
|
|
91
|
+
return [
|
|
92
|
+
key.slice(separator + 1)
|
|
93
|
+
];
|
|
94
|
+
}))
|
|
95
|
+
];
|
|
96
|
+
if (0 === routePaths.length) return;
|
|
97
|
+
if (hasUnsafePathEncoding(request.pathname)) return {
|
|
98
|
+
method: request.method,
|
|
99
|
+
routePath: request.pathname
|
|
100
|
+
};
|
|
101
|
+
const matches = routePaths.flatMap((routePath)=>{
|
|
102
|
+
const score = routeTemplateMatchScore(routePath, request.pathname);
|
|
103
|
+
return void 0 === score ? [] : [
|
|
104
|
+
{
|
|
105
|
+
routePath,
|
|
106
|
+
score
|
|
107
|
+
}
|
|
108
|
+
];
|
|
109
|
+
});
|
|
110
|
+
if (0 === matches.length) return {
|
|
111
|
+
method: request.method,
|
|
112
|
+
routePath: request.pathname
|
|
113
|
+
};
|
|
114
|
+
matches.sort((left, right)=>right.score - left.score);
|
|
115
|
+
return {
|
|
116
|
+
method: request.method,
|
|
117
|
+
routePath: matches[1]?.score === matches[0]?.score ? request.pathname : matches[0].routePath
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
const normalizeHeaderName = (headerName, fallback)=>(headerName || fallback).trim().toLowerCase();
|
|
121
|
+
const normalizeStatusCode = (statusCode)=>{
|
|
122
|
+
if ('number' == typeof statusCode && Number.isFinite(statusCode) && statusCode >= 400 && statusCode <= 599) return Math.floor(statusCode);
|
|
123
|
+
return DEFAULT_DENY_STATUS;
|
|
124
|
+
};
|
|
125
|
+
const readHeader = (headers, headerName)=>{
|
|
126
|
+
const lowerHeaderName = headerName.toLowerCase();
|
|
127
|
+
for (const [name, value] of Object.entries(headers || {}))if (name.toLowerCase() === lowerHeaderName) {
|
|
128
|
+
if (Array.isArray(value)) return value.length > 0 ? String(value[0]) : void 0;
|
|
129
|
+
if (null == value) return;
|
|
130
|
+
return String(value);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const extractNamespace = (requestId)=>requestId.split(/[/:.]/)[0]?.trim().toLowerCase();
|
|
134
|
+
const createViolation = (reason, message, status)=>({
|
|
135
|
+
code: 'BFF_CROSS_PROJECT_POLICY_DENIED',
|
|
136
|
+
reason,
|
|
137
|
+
message,
|
|
138
|
+
status
|
|
139
|
+
});
|
|
140
|
+
const warnAdvisoryNamespaceAllowlist = ()=>{
|
|
141
|
+
if (hasWarnedAdvisoryNamespaceAllowlist) return;
|
|
142
|
+
hasWarnedAdvisoryNamespaceAllowlist = true;
|
|
143
|
+
console.warn(`[Modern.js BFF] ${NAMESPACE_ALLOWLIST_REQUIRES_VERIFIER_MESSAGE}. allowClientAssertedNamespace=true will continue to evaluate allowlist against client-asserted requestId namespaces only.`);
|
|
144
|
+
};
|
|
145
|
+
const createCrossProjectPolicyEvaluationState = (headers, policy, observedRequest)=>({
|
|
146
|
+
headers,
|
|
147
|
+
policy,
|
|
148
|
+
status: normalizeStatusCode(policy.denyStatus),
|
|
149
|
+
requireEnvelope: policy.requireEnvelope ?? true,
|
|
150
|
+
requireOperationContext: policy.requireOperationContext ?? true,
|
|
151
|
+
requireOperationContextDetails: policy.requireOperationContextDetails ?? true,
|
|
152
|
+
requireOperationSchemaHash: policy.requireOperationSchemaHash ?? true,
|
|
153
|
+
requireOperationVersion: policy.requireOperationVersion ?? true,
|
|
154
|
+
allowUnknownOperations: policy.allowUnknownOperations ?? false,
|
|
155
|
+
allowClientAssertedNamespace: policy.allowClientAssertedNamespace ?? false,
|
|
156
|
+
verifyProducerIdentity: 'function' == typeof policy.verifyProducerIdentity ? policy.verifyProducerIdentity : void 0,
|
|
157
|
+
allowedNamespaces: (policy.allowedNamespaces || []).map((item)=>item.trim().toLowerCase()).filter(Boolean),
|
|
158
|
+
envelopeHeader: normalizeHeaderName(policy.envelopeHeader, BFF_ENVELOPE_HEADER),
|
|
159
|
+
operationContextHeader: normalizeHeaderName(policy.operationContextHeader, BFF_OPERATION_CONTEXT_HEADER),
|
|
160
|
+
operationContextDetailHeader: normalizeHeaderName(policy.operationContextDetailHeader, BFF_OPERATION_CONTEXT_DETAIL_HEADER),
|
|
161
|
+
requestId: '',
|
|
162
|
+
detailSchemaHash: '',
|
|
163
|
+
detailOperationVersion: void 0,
|
|
164
|
+
observedRequest: observedRequest ? {
|
|
165
|
+
method: String(observedRequest.method || '').trim().toUpperCase(),
|
|
166
|
+
routePath: String(observedRequest.routePath || '').trim()
|
|
167
|
+
} : void 0,
|
|
168
|
+
complete: false
|
|
169
|
+
});
|
|
170
|
+
const checkNamespaceAllowlistVerifier = (state)=>{
|
|
171
|
+
if (state.allowedNamespaces.length > 0 && void 0 === state.verifyProducerIdentity) {
|
|
172
|
+
if (!state.allowClientAssertedNamespace) return createViolation('producer_identity_mismatch', NAMESPACE_ALLOWLIST_REQUIRES_VERIFIER_MESSAGE, state.status);
|
|
173
|
+
warnAdvisoryNamespaceAllowlist();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const checkEnvelopeHeader = (state)=>{
|
|
177
|
+
const envelopeRaw = readHeader(state.headers, state.envelopeHeader);
|
|
178
|
+
if (!envelopeRaw) {
|
|
179
|
+
if (!state.requireEnvelope) {
|
|
180
|
+
state.complete = true;
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
return createViolation('missing_envelope', `Missing cross-project envelope header "${state.envelopeHeader}"`, state.status);
|
|
184
|
+
}
|
|
185
|
+
let envelope;
|
|
186
|
+
try {
|
|
187
|
+
const parsed = JSON.parse(envelopeRaw);
|
|
188
|
+
if (!parsed || 'object' != typeof parsed) throw new Error('invalid envelope object');
|
|
189
|
+
envelope = parsed;
|
|
190
|
+
} catch (_error) {
|
|
191
|
+
return createViolation('invalid_envelope', `Invalid cross-project envelope header "${state.envelopeHeader}"`, state.status);
|
|
192
|
+
}
|
|
193
|
+
const requestId = String(envelope.requestId || '').trim();
|
|
194
|
+
if (!requestId) return createViolation('missing_request_id', 'Cross-project envelope does not include a valid requestId', state.status);
|
|
195
|
+
state.requestId = requestId;
|
|
196
|
+
state.claimedNamespace = extractNamespace(requestId);
|
|
197
|
+
state.effectiveNamespace = state.claimedNamespace;
|
|
198
|
+
};
|
|
199
|
+
const checkProducerIdentity = (state)=>{
|
|
200
|
+
if (!state.verifyProducerIdentity) return;
|
|
201
|
+
const verifiedNamespaceRaw = state.verifyProducerIdentity(state.headers);
|
|
202
|
+
const verifiedNamespace = 'string' == typeof verifiedNamespaceRaw ? verifiedNamespaceRaw.trim().toLowerCase() : void 0;
|
|
203
|
+
if (!verifiedNamespace) return createViolation('producer_identity_mismatch', 'Producer identity could not be verified for request', state.status);
|
|
204
|
+
if (verifiedNamespace !== state.claimedNamespace) return createViolation('producer_identity_mismatch', `Envelope namespace "${state.claimedNamespace || 'unknown'}" does not match verified producer identity "${verifiedNamespace}"`, state.status);
|
|
205
|
+
state.effectiveNamespace = verifiedNamespace;
|
|
206
|
+
};
|
|
207
|
+
const checkNamespaceAllowlist = (state)=>{
|
|
208
|
+
if (state.allowedNamespaces.length > 0) {
|
|
209
|
+
if (!state.effectiveNamespace || !state.allowedNamespaces.includes(state.effectiveNamespace)) return createViolation('namespace_not_allowed', `Producer namespace "${state.effectiveNamespace || 'unknown'}" not allowed`, state.status);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
const checkOperationContext = (state)=>{
|
|
213
|
+
if (!state.requireOperationContext) {
|
|
214
|
+
state.complete = true;
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const operationContext = readHeader(state.headers, state.operationContextHeader);
|
|
218
|
+
if (!operationContext) return createViolation('missing_operation_context', `Missing operation context header "${state.operationContextHeader}"`, state.status);
|
|
219
|
+
if (!operationContext.startsWith(`${state.requestId}:`)) return createViolation('operation_context_mismatch', `Operation context header "${state.operationContextHeader}" does not match requestId "${state.requestId}"`, state.status);
|
|
220
|
+
state.operationContext = operationContext;
|
|
221
|
+
};
|
|
222
|
+
const checkOperationContextDetails = (state)=>{
|
|
223
|
+
const operationContextDetailsRaw = readHeader(state.headers, state.operationContextDetailHeader);
|
|
224
|
+
if (!operationContextDetailsRaw) {
|
|
225
|
+
if (state.requireOperationContextDetails) return createViolation('missing_operation_context_details', `Missing operation context details header "${state.operationContextDetailHeader}"`, state.status);
|
|
226
|
+
state.complete = true;
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
let operationContextDetails;
|
|
230
|
+
try {
|
|
231
|
+
const parsed = JSON.parse(operationContextDetailsRaw);
|
|
232
|
+
if (!parsed || 'object' != typeof parsed || Array.isArray(parsed)) throw new Error('invalid operation context details object');
|
|
233
|
+
operationContextDetails = parsed;
|
|
234
|
+
} catch (_error) {
|
|
235
|
+
return createViolation('invalid_operation_context_details', `Invalid operation context details header "${state.operationContextDetailHeader}"`, state.status);
|
|
236
|
+
}
|
|
237
|
+
const detailRequestId = String(operationContextDetails.requestId || '').trim();
|
|
238
|
+
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);
|
|
239
|
+
const detailOperationId = String(operationContextDetails.operationId || '').trim();
|
|
240
|
+
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);
|
|
241
|
+
state.operationContextDetails = operationContextDetails;
|
|
242
|
+
state.detailSchemaHash = String(operationContextDetails.schemaHash || '').trim();
|
|
243
|
+
if (state.requireOperationSchemaHash && !state.detailSchemaHash) return createViolation('missing_operation_schema_hash', `Operation context details header "${state.operationContextDetailHeader}" must include schemaHash`, state.status);
|
|
244
|
+
state.detailOperationVersion = operationContextDetails.operationVersion;
|
|
245
|
+
if (state.requireOperationVersion && 'number' != typeof state.detailOperationVersion) return createViolation('missing_operation_version', `Operation context details header "${state.operationContextDetailHeader}" must include operationVersion`, state.status);
|
|
246
|
+
};
|
|
247
|
+
const checkOperationContract = (state)=>{
|
|
248
|
+
if (!state.operationContextDetails) return;
|
|
249
|
+
const expectedContracts = state.policy.expectedOperationContracts;
|
|
250
|
+
if (expectedContracts && 'object' == typeof expectedContracts) {
|
|
251
|
+
const method = String(state.operationContextDetails.method || '').toUpperCase();
|
|
252
|
+
const routePath = String(state.operationContextDetails.routePath || '').trim();
|
|
253
|
+
const operationId = String(state.operationContextDetails.operationId || '').trim();
|
|
254
|
+
const observedMethod = state.observedRequest?.method;
|
|
255
|
+
const observedRoutePath = state.observedRequest?.routePath;
|
|
256
|
+
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);
|
|
257
|
+
const contractMethod = observedMethod || method;
|
|
258
|
+
const contractRoutePath = observedRoutePath || routePath;
|
|
259
|
+
const expectedContract = expectedContracts[`${contractMethod}:${contractRoutePath}`] || (state.observedRequest ? void 0 : expectedContracts[`operation:${operationId}`]);
|
|
260
|
+
if (expectedContract) {
|
|
261
|
+
const assertedOperationId = operationId || state.operationContext || '';
|
|
262
|
+
const canonicalRouteOperationId = `${state.requestId}:${contractMethod}:${contractRoutePath}`;
|
|
263
|
+
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);
|
|
264
|
+
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);
|
|
265
|
+
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);
|
|
266
|
+
} else if (!state.allowUnknownOperations) return createViolation('unknown_operation_contract', `No expected operation contract found for operation "${operationId || `${method}:${routePath}`}"`, state.status);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
const CROSS_PROJECT_POLICY_CHECKS = [
|
|
270
|
+
checkNamespaceAllowlistVerifier,
|
|
271
|
+
checkEnvelopeHeader,
|
|
272
|
+
checkProducerIdentity,
|
|
273
|
+
checkNamespaceAllowlist,
|
|
274
|
+
checkOperationContext,
|
|
275
|
+
checkOperationContextDetails,
|
|
276
|
+
checkOperationContract
|
|
277
|
+
];
|
|
278
|
+
const evaluateCrossProjectPolicy = (headers, policy, observedRequest)=>{
|
|
279
|
+
if (!policy?.enabled) return null;
|
|
280
|
+
const state = createCrossProjectPolicyEvaluationState(headers, policy, observedRequest);
|
|
281
|
+
for (const check of CROSS_PROJECT_POLICY_CHECKS){
|
|
282
|
+
const violation = check(state);
|
|
283
|
+
if (violation) return violation;
|
|
284
|
+
if (state.complete) break;
|
|
285
|
+
}
|
|
286
|
+
return null;
|
|
287
|
+
};
|
|
288
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
289
|
+
BFF_ENVELOPE_HEADER: BFF_ENVELOPE_HEADER,
|
|
290
|
+
BFF_OPERATION_CONTEXT_DETAIL_HEADER: BFF_OPERATION_CONTEXT_DETAIL_HEADER,
|
|
291
|
+
BFF_OPERATION_CONTEXT_HEADER: BFF_OPERATION_CONTEXT_HEADER,
|
|
292
|
+
evaluateCrossProjectPolicy: evaluateCrossProjectPolicy,
|
|
293
|
+
resolveCrossProjectRequestObservation: resolveCrossProjectRequestObservation
|
|
294
|
+
});
|
|
295
|
+
exports.BFF_ENVELOPE_HEADER = __webpack_exports__.BFF_ENVELOPE_HEADER;
|
|
296
|
+
exports.BFF_OPERATION_CONTEXT_DETAIL_HEADER = __webpack_exports__.BFF_OPERATION_CONTEXT_DETAIL_HEADER;
|
|
297
|
+
exports.BFF_OPERATION_CONTEXT_HEADER = __webpack_exports__.BFF_OPERATION_CONTEXT_HEADER;
|
|
298
|
+
exports.evaluateCrossProjectPolicy = __webpack_exports__.evaluateCrossProjectPolicy;
|
|
299
|
+
exports.resolveCrossProjectRequestObservation = __webpack_exports__.resolveCrossProjectRequestObservation;
|
|
300
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
301
|
+
"BFF_ENVELOPE_HEADER",
|
|
302
|
+
"BFF_OPERATION_CONTEXT_DETAIL_HEADER",
|
|
303
|
+
"BFF_OPERATION_CONTEXT_HEADER",
|
|
304
|
+
"evaluateCrossProjectPolicy",
|
|
305
|
+
"resolveCrossProjectRequestObservation"
|
|
306
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
307
|
+
Object.defineProperty(exports, '__esModule', {
|
|
308
|
+
value: true
|
|
309
|
+
});
|
|
@@ -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
|
+
});
|