@bleedingdev/modern-js-server-runtime-extensions 0.0.0-trusted-publisher-bootstrap
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/LICENSE +21 -0
- package/README.md +67 -0
- package/dist/cjs/contractGateAutopilot.js +162 -0
- package/dist/cjs/contractGateSnapshotStore.js +253 -0
- package/dist/cjs/env.js +58 -0
- package/dist/cjs/index.js +162 -0
- package/dist/cjs/mfCache.js +106 -0
- package/dist/cjs/moduleFederationCss.js +285 -0
- package/dist/cjs/runtimeFallbackSignal.js +311 -0
- package/dist/cjs/telemetry.js +373 -0
- package/dist/cjs/telemetryCore.js +819 -0
- package/dist/esm/contractGateAutopilot.mjs +124 -0
- package/dist/esm/contractGateSnapshotStore.mjs +190 -0
- package/dist/esm/env.mjs +17 -0
- package/dist/esm/index.mjs +6 -0
- package/dist/esm/mfCache.mjs +55 -0
- package/dist/esm/moduleFederationCss.mjs +225 -0
- package/dist/esm/runtimeFallbackSignal.mjs +222 -0
- package/dist/esm/telemetry.mjs +275 -0
- package/dist/esm/telemetryCore.mjs +759 -0
- package/dist/esm-node/contractGateAutopilot.mjs +125 -0
- package/dist/esm-node/contractGateSnapshotStore.mjs +192 -0
- package/dist/esm-node/env.mjs +18 -0
- package/dist/esm-node/index.mjs +7 -0
- package/dist/esm-node/mfCache.mjs +56 -0
- package/dist/esm-node/moduleFederationCss.mjs +226 -0
- package/dist/esm-node/runtimeFallbackSignal.mjs +223 -0
- package/dist/esm-node/telemetry.mjs +276 -0
- package/dist/esm-node/telemetryCore.mjs +760 -0
- package/dist/types/contractGateAutopilot.d.ts +35 -0
- package/dist/types/contractGateSnapshotStore.d.ts +57 -0
- package/dist/types/env.d.ts +40 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/mfCache.d.ts +27 -0
- package/dist/types/moduleFederationCss.d.ts +87 -0
- package/dist/types/runtimeFallbackSignal.d.ts +94 -0
- package/dist/types/telemetry.d.ts +12 -0
- package/dist/types/telemetryCore.d.ts +257 -0
- package/package.json +69 -0
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +7 -0
- package/src/contractGateAutopilot.ts +247 -0
- package/src/contractGateSnapshotStore.ts +420 -0
- package/src/env.ts +63 -0
- package/src/index.ts +84 -0
- package/src/mfCache.ts +119 -0
- package/src/moduleFederationCss.ts +473 -0
- package/src/runtimeFallbackSignal.ts +584 -0
- package/src/telemetry.ts +554 -0
- package/src/telemetryCore.ts +1332 -0
- package/tests/contractGateAutopilot.test.ts +203 -0
- package/tests/contractGateSnapshotStore.test.ts +223 -0
- package/tests/env.test.ts +73 -0
- package/tests/helpers.ts +19 -0
- package/tests/mfCache.test.ts +150 -0
- package/tests/moduleFederationCss.test.ts +392 -0
- package/tests/registration.test.ts +112 -0
- package/tests/telemetry.test.ts +360 -0
- package/tests/telemetryAutopilot.test.ts +993 -0
- package/tests/telemetryCanaryOrchestrator.test.ts +140 -0
- package/tests/telemetryLifecycle.test.ts +168 -0
- package/tests/telemetryTraceparent.test.ts +167 -0
- package/tests/tsconfig.json +11 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,311 @@
|
|
|
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_RUNTIME_FALLBACK_FAILURE_HOLD_MS: ()=>DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS,
|
|
32
|
+
DEFAULT_RUNTIME_FALLBACK_GATE_NAME: ()=>DEFAULT_RUNTIME_FALLBACK_GATE_NAME,
|
|
33
|
+
DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES: ()=>DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES,
|
|
34
|
+
DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT: ()=>DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT,
|
|
35
|
+
DEFAULT_RUNTIME_STATUS_ENDPOINT: ()=>DEFAULT_RUNTIME_STATUS_ENDPOINT,
|
|
36
|
+
createRuntimeFallbackSignalRuntimeState: ()=>createRuntimeFallbackSignalRuntimeState,
|
|
37
|
+
createRuntimeSignalError: ()=>createRuntimeSignalError,
|
|
38
|
+
enforceRuntimeFallbackSignalAuth: ()=>enforceRuntimeFallbackSignalAuth,
|
|
39
|
+
enforceRuntimeFallbackSignalAuthToken: ()=>enforceRuntimeFallbackSignalAuthToken,
|
|
40
|
+
enforceRuntimeFallbackSignalTrustPolicy: ()=>enforceRuntimeFallbackSignalTrustPolicy,
|
|
41
|
+
getRuntimeSignalErrorStatusCode: ()=>getRuntimeSignalErrorStatusCode,
|
|
42
|
+
normalizeRequiredRuntimeFallbackSignalAuthConfig: ()=>normalizeRequiredRuntimeFallbackSignalAuthConfig,
|
|
43
|
+
normalizeRuntimeFallbackSignalAuthConfig: ()=>normalizeRuntimeFallbackSignalAuthConfig,
|
|
44
|
+
normalizeRuntimeFallbackTrustPolicy: ()=>normalizeRuntimeFallbackTrustPolicy,
|
|
45
|
+
parseRuntimeFallbackSignalPayload: ()=>parseRuntimeFallbackSignalPayload,
|
|
46
|
+
parseRuntimeFallbackSignalPayloadFromRawBody: ()=>parseRuntimeFallbackSignalPayloadFromRawBody,
|
|
47
|
+
persistRuntimeFallbackContractGate: ()=>persistRuntimeFallbackContractGate,
|
|
48
|
+
resolveRuntimeFallbackSignalEndpoint: ()=>resolveRuntimeFallbackSignalEndpoint
|
|
49
|
+
});
|
|
50
|
+
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
51
|
+
const external_contractGateSnapshotStore_js_namespaceObject = require("./contractGateSnapshotStore.js");
|
|
52
|
+
const DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = '/_modern/contract-gates/runtime-fallback';
|
|
53
|
+
const DEFAULT_RUNTIME_STATUS_ENDPOINT = '/_modern/runtime/status';
|
|
54
|
+
const DEFAULT_RUNTIME_FALLBACK_GATE_NAME = 'runtime-mf-fallback-health';
|
|
55
|
+
const DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS = 300000;
|
|
56
|
+
const DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES = 16384;
|
|
57
|
+
const DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER = 'x-modernjs-runtime-signal-token';
|
|
58
|
+
const DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW = 30;
|
|
59
|
+
const DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS = 60000;
|
|
60
|
+
const DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS = 10000;
|
|
61
|
+
function resolveRuntimeFallbackSignalEndpoint(configuredEndpoint) {
|
|
62
|
+
const rawEndpoint = configuredEndpoint?.trim();
|
|
63
|
+
if (!rawEndpoint) return DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT;
|
|
64
|
+
if (rawEndpoint.startsWith('/')) return rawEndpoint;
|
|
65
|
+
try {
|
|
66
|
+
return new URL(rawEndpoint).pathname || DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT;
|
|
67
|
+
} catch (_error) {
|
|
68
|
+
return `/${rawEndpoint.replace(/^\/+/, '')}`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function createRuntimeSignalError(message, code) {
|
|
72
|
+
const error = new Error(message);
|
|
73
|
+
error.code = code;
|
|
74
|
+
return error;
|
|
75
|
+
}
|
|
76
|
+
function getUtf8ByteLength(input) {
|
|
77
|
+
if ("u" > typeof Buffer) return Buffer.byteLength(input);
|
|
78
|
+
return new TextEncoder().encode(input).length;
|
|
79
|
+
}
|
|
80
|
+
function normalizeRuntimeSignalOrigin(value) {
|
|
81
|
+
if ('string' != typeof value || 0 === value.trim().length) return;
|
|
82
|
+
try {
|
|
83
|
+
return new URL(value).origin;
|
|
84
|
+
} catch (_error) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function normalizeRuntimeSignalAppName(payload) {
|
|
89
|
+
if ('string' != typeof payload.appName) return 'unknown';
|
|
90
|
+
const normalized = payload.appName.trim();
|
|
91
|
+
return normalized.length > 0 ? normalized : 'unknown';
|
|
92
|
+
}
|
|
93
|
+
function normalizeRuntimeSignalRuntimeDigest(payload) {
|
|
94
|
+
if ('string' == typeof payload.runtimeDigest && payload.runtimeDigest.trim()) return payload.runtimeDigest.trim();
|
|
95
|
+
const metadata = payload.metadata;
|
|
96
|
+
if (metadata && 'object' == typeof metadata && !Array.isArray(metadata) && 'string' == typeof metadata.runtimeDigest) {
|
|
97
|
+
const digest = String(metadata.runtimeDigest).trim();
|
|
98
|
+
if (digest) return digest;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function normalizeRuntimeFallbackSignalAuthConfig(configured) {
|
|
102
|
+
const headerName = 'string' == typeof configured?.headerName && configured.headerName.trim() ? configured.headerName.trim().toLowerCase() : DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER;
|
|
103
|
+
const expectedFromEnv = 'string' == typeof configured?.expectedValueEnv && configured.expectedValueEnv.trim().length > 0 ? process.env[configured.expectedValueEnv.trim()] : void 0;
|
|
104
|
+
const expectedFromConfig = 'string' == typeof configured?.expectedValue && configured.expectedValue.trim().length > 0 ? configured.expectedValue.trim() : void 0;
|
|
105
|
+
const expectedValue = expectedFromConfig || expectedFromEnv;
|
|
106
|
+
const enabled = configured?.enabled === true;
|
|
107
|
+
if (enabled && !expectedValue) throw new Error('[telemetry.canary.autopilot.runtimeFallbackSignal] auth.enabled is true but no expected token is configured');
|
|
108
|
+
return {
|
|
109
|
+
enabled,
|
|
110
|
+
headerName,
|
|
111
|
+
expectedValue
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function normalizeRequiredRuntimeFallbackSignalAuthConfig(configured) {
|
|
115
|
+
if (configured?.enabled === false) throw new Error('[telemetry.canary.autopilot.runtimeFallbackSignal] the endpoint cannot be enabled with auth disabled; configure auth.expectedValue or auth.expectedValueEnv');
|
|
116
|
+
try {
|
|
117
|
+
return normalizeRuntimeFallbackSignalAuthConfig({
|
|
118
|
+
...configured,
|
|
119
|
+
enabled: true
|
|
120
|
+
});
|
|
121
|
+
} catch (_error) {
|
|
122
|
+
throw new Error('[telemetry.canary.autopilot.runtimeFallbackSignal] enabling the endpoint requires an auth token; configure auth.expectedValue or auth.expectedValueEnv');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function safeTokenEquals(candidate, expected) {
|
|
126
|
+
const candidateDigest = (0, external_node_crypto_namespaceObject.createHash)('sha256').update(candidate).digest();
|
|
127
|
+
const expectedDigest = (0, external_node_crypto_namespaceObject.createHash)('sha256').update(expected).digest();
|
|
128
|
+
return (0, external_node_crypto_namespaceObject.timingSafeEqual)(candidateDigest, expectedDigest);
|
|
129
|
+
}
|
|
130
|
+
function enforceRuntimeFallbackSignalAuthToken(token, authConfig) {
|
|
131
|
+
if (!authConfig.enabled) return;
|
|
132
|
+
if (!token || !authConfig.expectedValue || !safeTokenEquals(token, authConfig.expectedValue)) throw createRuntimeSignalError('runtime fallback signal auth failed', 'UNAUTHORIZED');
|
|
133
|
+
}
|
|
134
|
+
function enforceRuntimeFallbackSignalAuth(c, runtimeSignalConfig) {
|
|
135
|
+
enforceRuntimeFallbackSignalAuthToken(c.req.header(runtimeSignalConfig.auth.headerName), runtimeSignalConfig.auth);
|
|
136
|
+
}
|
|
137
|
+
function normalizeRuntimeFallbackTrustPolicy(configured) {
|
|
138
|
+
const allowedApps = Array.isArray(configured?.allowedApps) ? configured.allowedApps.map((item)=>'string' == typeof item ? item.trim() : '').filter(Boolean) : [];
|
|
139
|
+
const allowedEntryOrigins = Array.isArray(configured?.allowedEntryOrigins) ? configured.allowedEntryOrigins.map((item)=>normalizeRuntimeSignalOrigin(item)).filter((item)=>Boolean(item)) : [];
|
|
140
|
+
const expectedRuntimeDigestsRaw = configured?.expectedRuntimeDigests || {};
|
|
141
|
+
const expectedRuntimeDigests = {};
|
|
142
|
+
Object.entries(expectedRuntimeDigestsRaw).forEach(([appName, digest])=>{
|
|
143
|
+
if ('string' == typeof appName && appName.trim().length > 0 && 'string' == typeof digest && digest.trim().length > 0) expectedRuntimeDigests[appName.trim()] = digest.trim();
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
allowedApps,
|
|
147
|
+
allowedEntryOrigins,
|
|
148
|
+
expectedRuntimeDigests,
|
|
149
|
+
enforceRuntimeDigest: configured?.enforceRuntimeDigest === true,
|
|
150
|
+
maxSignalsPerWindow: Math.max(1, Math.floor(configured?.maxSignalsPerWindow ?? DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW)),
|
|
151
|
+
windowMs: Math.max(1000, Math.floor(configured?.windowMs ?? DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS)),
|
|
152
|
+
dedupeWindowMs: Math.max(0, Math.floor(configured?.dedupeWindowMs ?? DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS))
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function createRuntimeFallbackSignalRuntimeState() {
|
|
156
|
+
return {
|
|
157
|
+
rateLimitBySource: new Map(),
|
|
158
|
+
dedupeByFingerprint: new Map()
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function cleanupRuntimeFallbackSignalRuntimeState(now, runtimeState, trustPolicy) {
|
|
162
|
+
const dedupeExpiryMs = Math.max(trustPolicy.dedupeWindowMs, trustPolicy.windowMs, 1000);
|
|
163
|
+
runtimeState.dedupeByFingerprint.forEach((lastSeenAt, fingerprint)=>{
|
|
164
|
+
if (now - lastSeenAt > dedupeExpiryMs) runtimeState.dedupeByFingerprint.delete(fingerprint);
|
|
165
|
+
});
|
|
166
|
+
runtimeState.rateLimitBySource.forEach((state, source)=>{
|
|
167
|
+
if (now - state.windowStartedAt > 2 * trustPolicy.windowMs) runtimeState.rateLimitBySource.delete(source);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function enforceRuntimeFallbackSignalTrustPolicy(payload, runtimeSignalContext, source = {}) {
|
|
171
|
+
const { trustPolicy, runtimeState } = runtimeSignalContext;
|
|
172
|
+
const now = Date.now();
|
|
173
|
+
cleanupRuntimeFallbackSignalRuntimeState(now, runtimeState, trustPolicy);
|
|
174
|
+
const appName = normalizeRuntimeSignalAppName(payload);
|
|
175
|
+
const entryOrigin = normalizeRuntimeSignalOrigin(payload.entry);
|
|
176
|
+
const runtimeDigest = normalizeRuntimeSignalRuntimeDigest(payload);
|
|
177
|
+
if (trustPolicy.allowedApps.length > 0 && !trustPolicy.allowedApps.includes(appName)) throw createRuntimeSignalError(`runtime fallback signal app "${appName}" is not trusted`, 'UNTRUSTED_SOURCE');
|
|
178
|
+
if (trustPolicy.allowedEntryOrigins.length > 0) {
|
|
179
|
+
if (!entryOrigin || !trustPolicy.allowedEntryOrigins.includes(entryOrigin)) throw createRuntimeSignalError(`runtime fallback signal entry origin "${entryOrigin || 'unknown'}" is not trusted`, 'UNTRUSTED_SOURCE');
|
|
180
|
+
}
|
|
181
|
+
const expectedDigest = trustPolicy.expectedRuntimeDigests[appName];
|
|
182
|
+
if (expectedDigest && runtimeDigest !== expectedDigest) throw createRuntimeSignalError(`runtime fallback runtimeDigest mismatch for app "${appName}"`, 'UNTRUSTED_SOURCE');
|
|
183
|
+
if (trustPolicy.enforceRuntimeDigest && !runtimeDigest) throw createRuntimeSignalError(`runtime fallback signal for app "${appName}" is missing runtimeDigest`, 'UNTRUSTED_SOURCE');
|
|
184
|
+
const dedupeFingerprint = JSON.stringify({
|
|
185
|
+
appName,
|
|
186
|
+
entryOrigin: entryOrigin || 'unknown',
|
|
187
|
+
reason: payload.reason || 'runtime_fallback',
|
|
188
|
+
phase: payload.phase || 'unknown',
|
|
189
|
+
runtimeDigest: runtimeDigest || 'unknown'
|
|
190
|
+
});
|
|
191
|
+
const dedupeWindowMs = trustPolicy.dedupeWindowMs;
|
|
192
|
+
if (dedupeWindowMs > 0) {
|
|
193
|
+
const lastSeenAt = runtimeState.dedupeByFingerprint.get(dedupeFingerprint);
|
|
194
|
+
runtimeState.dedupeByFingerprint.set(dedupeFingerprint, now);
|
|
195
|
+
if ('number' == typeof lastSeenAt && now - lastSeenAt <= dedupeWindowMs) return {
|
|
196
|
+
deduped: true
|
|
197
|
+
};
|
|
198
|
+
} else runtimeState.dedupeByFingerprint.set(dedupeFingerprint, now);
|
|
199
|
+
const remoteAddress = source.remoteAddress?.trim();
|
|
200
|
+
const sourceKey = remoteAddress || 'unknown-remote';
|
|
201
|
+
const rateState = runtimeState.rateLimitBySource.get(sourceKey);
|
|
202
|
+
if (!rateState || now - rateState.windowStartedAt > trustPolicy.windowMs) runtimeState.rateLimitBySource.set(sourceKey, {
|
|
203
|
+
count: 1,
|
|
204
|
+
windowStartedAt: now
|
|
205
|
+
});
|
|
206
|
+
else {
|
|
207
|
+
if (rateState.count >= trustPolicy.maxSignalsPerWindow) throw createRuntimeSignalError(`runtime fallback signal rate-limited for source "${sourceKey}"`, 'RATE_LIMITED');
|
|
208
|
+
rateState.count += 1;
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
deduped: false
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
async function parseRuntimeFallbackSignalPayload(c, maxBodyBytes) {
|
|
215
|
+
const contentLengthHeader = c.req.header('content-length');
|
|
216
|
+
if (contentLengthHeader) {
|
|
217
|
+
const contentLength = Number.parseInt(contentLengthHeader, 10);
|
|
218
|
+
if (Number.isFinite(contentLength) && contentLength > maxBodyBytes) throw createRuntimeSignalError('runtime fallback signal payload too large', 'PAYLOAD_TOO_LARGE');
|
|
219
|
+
}
|
|
220
|
+
const rawBody = await c.req.raw.text();
|
|
221
|
+
const payload = parseRuntimeFallbackSignalPayloadFromRawBody(rawBody, maxBodyBytes);
|
|
222
|
+
return {
|
|
223
|
+
rawBody,
|
|
224
|
+
payload
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function parseRuntimeFallbackSignalPayloadFromRawBody(rawBody, maxBodyBytes) {
|
|
228
|
+
if (!rawBody || 0 === rawBody.trim().length) throw createRuntimeSignalError('runtime fallback signal body is empty', 'INVALID_PAYLOAD');
|
|
229
|
+
if (getUtf8ByteLength(rawBody) > maxBodyBytes) throw createRuntimeSignalError('runtime fallback signal payload too large', 'PAYLOAD_TOO_LARGE');
|
|
230
|
+
let payload;
|
|
231
|
+
try {
|
|
232
|
+
payload = JSON.parse(rawBody);
|
|
233
|
+
} catch (_error) {
|
|
234
|
+
throw createRuntimeSignalError('runtime fallback signal body must be valid JSON', 'INVALID_PAYLOAD');
|
|
235
|
+
}
|
|
236
|
+
if (!payload || 'object' != typeof payload || Array.isArray(payload)) throw createRuntimeSignalError('runtime fallback signal body must be a JSON object', 'INVALID_PAYLOAD');
|
|
237
|
+
return payload;
|
|
238
|
+
}
|
|
239
|
+
function getRuntimeSignalErrorStatusCode(signalError) {
|
|
240
|
+
if ('PAYLOAD_TOO_LARGE' === signalError.code) return 413;
|
|
241
|
+
if ('INVALID_PAYLOAD' === signalError.code) return 400;
|
|
242
|
+
if ('UNAUTHORIZED' === signalError.code) return 401;
|
|
243
|
+
if ('RATE_LIMITED' === signalError.code) return 429;
|
|
244
|
+
if ('UNTRUSTED_SOURCE' === signalError.code) return 403;
|
|
245
|
+
return 500;
|
|
246
|
+
}
|
|
247
|
+
async function persistRuntimeFallbackContractGate(payload, runtimeSignalConfig) {
|
|
248
|
+
const now = Date.now();
|
|
249
|
+
const gateSnapshotStore = await runtimeSignalConfig.gateSnapshotStore;
|
|
250
|
+
const snapshot = await gateSnapshotStore.readSnapshot() || {};
|
|
251
|
+
const existingGates = snapshot.gates && 'object' == typeof snapshot.gates ? snapshot.gates : {};
|
|
252
|
+
const reason = 'string' == typeof payload.reason ? payload.reason : 'runtime_fallback';
|
|
253
|
+
const phase = 'string' == typeof payload.phase ? payload.phase : 'unknown';
|
|
254
|
+
const appName = 'string' == typeof payload.appName ? payload.appName : 'unknown';
|
|
255
|
+
const entry = 'string' == typeof payload.entry ? payload.entry : void 0;
|
|
256
|
+
snapshot.schemaVersion = 'number' == typeof snapshot.schemaVersion ? snapshot.schemaVersion : external_contractGateSnapshotStore_js_namespaceObject.CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION;
|
|
257
|
+
snapshot.updatedAt = now;
|
|
258
|
+
snapshot.gates = {
|
|
259
|
+
...existingGates,
|
|
260
|
+
[runtimeSignalConfig.gateName]: {
|
|
261
|
+
passed: false,
|
|
262
|
+
reason: `runtime_fallback:${reason} phase=${phase} app=${appName}${entry ? ` entry=${entry}` : ''}`,
|
|
263
|
+
updatedAt: now,
|
|
264
|
+
expiresAt: now + runtimeSignalConfig.failureHoldMs,
|
|
265
|
+
source: 'runtime-mf-fallback-signal',
|
|
266
|
+
metadata: payload
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
await gateSnapshotStore.writeSnapshot(snapshot);
|
|
270
|
+
}
|
|
271
|
+
exports.DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS;
|
|
272
|
+
exports.DEFAULT_RUNTIME_FALLBACK_GATE_NAME = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_GATE_NAME;
|
|
273
|
+
exports.DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES;
|
|
274
|
+
exports.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT;
|
|
275
|
+
exports.DEFAULT_RUNTIME_STATUS_ENDPOINT = __webpack_exports__.DEFAULT_RUNTIME_STATUS_ENDPOINT;
|
|
276
|
+
exports.createRuntimeFallbackSignalRuntimeState = __webpack_exports__.createRuntimeFallbackSignalRuntimeState;
|
|
277
|
+
exports.createRuntimeSignalError = __webpack_exports__.createRuntimeSignalError;
|
|
278
|
+
exports.enforceRuntimeFallbackSignalAuth = __webpack_exports__.enforceRuntimeFallbackSignalAuth;
|
|
279
|
+
exports.enforceRuntimeFallbackSignalAuthToken = __webpack_exports__.enforceRuntimeFallbackSignalAuthToken;
|
|
280
|
+
exports.enforceRuntimeFallbackSignalTrustPolicy = __webpack_exports__.enforceRuntimeFallbackSignalTrustPolicy;
|
|
281
|
+
exports.getRuntimeSignalErrorStatusCode = __webpack_exports__.getRuntimeSignalErrorStatusCode;
|
|
282
|
+
exports.normalizeRequiredRuntimeFallbackSignalAuthConfig = __webpack_exports__.normalizeRequiredRuntimeFallbackSignalAuthConfig;
|
|
283
|
+
exports.normalizeRuntimeFallbackSignalAuthConfig = __webpack_exports__.normalizeRuntimeFallbackSignalAuthConfig;
|
|
284
|
+
exports.normalizeRuntimeFallbackTrustPolicy = __webpack_exports__.normalizeRuntimeFallbackTrustPolicy;
|
|
285
|
+
exports.parseRuntimeFallbackSignalPayload = __webpack_exports__.parseRuntimeFallbackSignalPayload;
|
|
286
|
+
exports.parseRuntimeFallbackSignalPayloadFromRawBody = __webpack_exports__.parseRuntimeFallbackSignalPayloadFromRawBody;
|
|
287
|
+
exports.persistRuntimeFallbackContractGate = __webpack_exports__.persistRuntimeFallbackContractGate;
|
|
288
|
+
exports.resolveRuntimeFallbackSignalEndpoint = __webpack_exports__.resolveRuntimeFallbackSignalEndpoint;
|
|
289
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
290
|
+
"DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS",
|
|
291
|
+
"DEFAULT_RUNTIME_FALLBACK_GATE_NAME",
|
|
292
|
+
"DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES",
|
|
293
|
+
"DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT",
|
|
294
|
+
"DEFAULT_RUNTIME_STATUS_ENDPOINT",
|
|
295
|
+
"createRuntimeFallbackSignalRuntimeState",
|
|
296
|
+
"createRuntimeSignalError",
|
|
297
|
+
"enforceRuntimeFallbackSignalAuth",
|
|
298
|
+
"enforceRuntimeFallbackSignalAuthToken",
|
|
299
|
+
"enforceRuntimeFallbackSignalTrustPolicy",
|
|
300
|
+
"getRuntimeSignalErrorStatusCode",
|
|
301
|
+
"normalizeRequiredRuntimeFallbackSignalAuthConfig",
|
|
302
|
+
"normalizeRuntimeFallbackSignalAuthConfig",
|
|
303
|
+
"normalizeRuntimeFallbackTrustPolicy",
|
|
304
|
+
"parseRuntimeFallbackSignalPayload",
|
|
305
|
+
"parseRuntimeFallbackSignalPayloadFromRawBody",
|
|
306
|
+
"persistRuntimeFallbackContractGate",
|
|
307
|
+
"resolveRuntimeFallbackSignalEndpoint"
|
|
308
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
309
|
+
Object.defineProperty(exports, '__esModule', {
|
|
310
|
+
value: true
|
|
311
|
+
});
|