@bleedingdev/modern-js-server-runtime-extensions 3.8.3-ultramodern.1 → 3.8.3-ultramodern.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/backend-federation-security/index.js +415 -0
- package/dist/cjs/backend-federation-security/node.js +74 -0
- package/dist/cjs/contract-gate-snapshot-store/http-store.js +1 -1
- package/dist/cjs/contract-gate-snapshot-store/resolve.js +4 -4
- package/dist/cjs/{contractGateAutopilot.js → contractGateSnapshotObserver.js} +14 -17
- package/dist/cjs/index.js +45 -13
- package/dist/cjs/runtime-fallback-signal/resolver.js +3 -3
- package/dist/cjs/runtimeLifecycle.js +129 -0
- package/dist/cjs/telemetry/{canaryEvaluation.js → healthEvaluation.js} +11 -13
- package/dist/cjs/telemetry/{canary.js → healthMonitor.js} +27 -44
- package/dist/cjs/telemetry/{canarySetup.js → healthSetup.js} +35 -39
- package/dist/cjs/telemetry/lifecycle.js +14 -14
- package/dist/cjs/telemetry/plugin.js +9 -9
- package/dist/cjs/telemetry/runtimeEndpoints.js +3 -3
- package/dist/cjs/telemetryCore.js +4 -4
- package/dist/esm/backend-federation-security/index.mjs +361 -0
- package/dist/esm/backend-federation-security/node.mjs +30 -0
- package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -1
- package/dist/esm/contract-gate-snapshot-store/resolve.mjs +4 -4
- package/dist/esm/{contractGateAutopilot.mjs → contractGateSnapshotObserver.mjs} +12 -15
- package/dist/esm/index.mjs +4 -2
- package/dist/esm/runtime-fallback-signal/resolver.mjs +3 -3
- package/dist/esm/runtimeLifecycle.mjs +82 -0
- package/dist/esm/telemetry/{canaryEvaluation.mjs → healthEvaluation.mjs} +9 -11
- package/dist/esm/telemetry/{canary.mjs → healthMonitor.mjs} +25 -42
- package/dist/esm/telemetry/healthSetup.mjs +65 -0
- package/dist/esm/telemetry/lifecycle.mjs +14 -14
- package/dist/esm/telemetry/plugin.mjs +8 -8
- package/dist/esm/telemetry/runtimeEndpoints.mjs +3 -3
- package/dist/esm/telemetryCore.mjs +1 -1
- package/dist/esm-node/backend-federation-security/index.mjs +362 -0
- package/dist/esm-node/backend-federation-security/node.mjs +31 -0
- package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +1 -1
- package/dist/esm-node/contract-gate-snapshot-store/resolve.mjs +4 -4
- package/dist/esm-node/{contractGateAutopilot.mjs → contractGateSnapshotObserver.mjs} +12 -15
- package/dist/esm-node/index.mjs +4 -2
- package/dist/esm-node/runtime-fallback-signal/resolver.mjs +3 -3
- package/dist/esm-node/runtimeLifecycle.mjs +83 -0
- package/dist/esm-node/telemetry/{canaryEvaluation.mjs → healthEvaluation.mjs} +9 -11
- package/dist/esm-node/telemetry/{canary.mjs → healthMonitor.mjs} +25 -42
- package/dist/esm-node/telemetry/healthSetup.mjs +66 -0
- package/dist/esm-node/telemetry/lifecycle.mjs +14 -14
- package/dist/esm-node/telemetry/plugin.mjs +8 -8
- package/dist/esm-node/telemetry/runtimeEndpoints.mjs +3 -3
- package/dist/esm-node/telemetryCore.mjs +1 -1
- package/dist/types/backend-federation-security/index.d.ts +68 -0
- package/dist/types/backend-federation-security/node.d.ts +3 -0
- package/dist/types/{contractGateAutopilot.d.ts → contractGateSnapshotObserver.d.ts} +7 -6
- package/dist/types/index.d.ts +4 -2
- package/dist/types/runtime-fallback-signal/resolver.d.ts +2 -2
- package/dist/types/runtimeLifecycle.d.ts +10 -0
- package/dist/types/telemetry/healthEvaluation.d.ts +20 -0
- package/dist/types/telemetry/{canary.d.ts → healthMonitor.d.ts} +31 -28
- package/dist/types/telemetry/{canarySetup.d.ts → healthSetup.d.ts} +6 -6
- package/dist/types/telemetry/lifecycle.d.ts +4 -4
- package/dist/types/telemetry/plugin.d.ts +1 -1
- package/dist/types/telemetry/runtimeEndpoints.d.ts +3 -3
- package/dist/types/telemetryCore.d.ts +1 -1
- package/package.json +46 -8
- package/src/backend-federation-security/index.ts +831 -0
- package/src/backend-federation-security/node.ts +51 -0
- package/src/contract-gate-snapshot-store/http-store.ts +1 -1
- package/src/contract-gate-snapshot-store/resolve.ts +4 -4
- package/src/{contractGateAutopilot.ts → contractGateSnapshotObserver.ts} +18 -25
- package/src/index.ts +42 -6
- package/src/runtime-fallback-signal/resolver.ts +5 -5
- package/src/runtimeLifecycle.ts +125 -0
- package/src/telemetry/{canaryEvaluation.ts → healthEvaluation.ts} +14 -17
- package/src/telemetry/{canary.ts → healthMonitor.ts} +72 -84
- package/src/telemetry/{canarySetup.ts → healthSetup.ts} +50 -53
- package/src/telemetry/lifecycle.ts +20 -20
- package/src/telemetry/plugin.ts +16 -16
- package/src/telemetry/runtimeEndpoints.ts +6 -6
- package/src/telemetryCore.ts +11 -11
- package/tests/backendFederationSecurity.test.ts +416 -0
- package/tests/{contractGateAutopilot.test.ts → contractGateSnapshotObserver.test.ts} +59 -62
- package/tests/runtimeLifecycle.test.ts +107 -0
- package/tests/telemetryHealthMonitor.test.ts +187 -0
- package/dist/esm/telemetry/canarySetup.mjs +0 -69
- package/dist/esm-node/telemetry/canarySetup.mjs +0 -70
- package/dist/types/telemetry/canaryEvaluation.d.ts +0 -20
- package/tests/telemetryCanaryOrchestrator.test.ts +0 -365
|
@@ -0,0 +1,831 @@
|
|
|
1
|
+
const DEFAULT_MAX_ENTRY_BYTES = 16 * 1024 * 1024;
|
|
2
|
+
const DEFAULT_MAX_RESOURCE_BYTES = 1024 * 1024;
|
|
3
|
+
const DEFAULT_ENTRY_TIMEOUT_MS = 10_000;
|
|
4
|
+
|
|
5
|
+
export type BackendFederationRemoteEntryErrorCode =
|
|
6
|
+
| 'aborted'
|
|
7
|
+
| 'byte_length_mismatch'
|
|
8
|
+
| 'entry_too_large'
|
|
9
|
+
| 'fetch_failed'
|
|
10
|
+
| 'identity_mismatch'
|
|
11
|
+
| 'integrity_mismatch'
|
|
12
|
+
| 'invalid_verification'
|
|
13
|
+
| 'redirect_mismatch'
|
|
14
|
+
| 'timeout'
|
|
15
|
+
| 'unsupported_entry';
|
|
16
|
+
|
|
17
|
+
export class BackendFederationRemoteEntryError extends Error {
|
|
18
|
+
readonly code: BackendFederationRemoteEntryErrorCode;
|
|
19
|
+
readonly details?: Record<string, unknown>;
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
code: BackendFederationRemoteEntryErrorCode,
|
|
23
|
+
message: string,
|
|
24
|
+
options: {
|
|
25
|
+
cause?: unknown;
|
|
26
|
+
details?: Record<string, unknown>;
|
|
27
|
+
} = {},
|
|
28
|
+
) {
|
|
29
|
+
super(message, options.cause === undefined ? undefined : options);
|
|
30
|
+
this.name = 'BackendFederationRemoteEntryError';
|
|
31
|
+
this.code = code;
|
|
32
|
+
this.details = options.details;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type BackendFederationEntryIntegrity = {
|
|
37
|
+
byteLength: number;
|
|
38
|
+
sha256: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type BackendFederationRemoteEntryVerification =
|
|
42
|
+
BackendFederationEntryIntegrity & {
|
|
43
|
+
buildMarker?: string;
|
|
44
|
+
entryUrl: string;
|
|
45
|
+
remoteName: string;
|
|
46
|
+
unitId?: string;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type BackendFederationRemoteEntryExpectation =
|
|
50
|
+
Partial<BackendFederationRemoteEntryVerification>;
|
|
51
|
+
|
|
52
|
+
export type BackendFederationRemoteEntry = {
|
|
53
|
+
entry: string;
|
|
54
|
+
name: string;
|
|
55
|
+
type?: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type BackendFederationEntryExports = {
|
|
59
|
+
get: (
|
|
60
|
+
id: string,
|
|
61
|
+
) =>
|
|
62
|
+
| (() => Promise<unknown> | unknown)
|
|
63
|
+
| Promise<() => Promise<unknown> | unknown>;
|
|
64
|
+
init?: (...args: unknown[]) => void | Promise<void>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type BackendFederationResourceResponse = {
|
|
68
|
+
body?: ReadableStream<Uint8Array> | null;
|
|
69
|
+
headers?: { get(name: string): string | null };
|
|
70
|
+
ok: boolean;
|
|
71
|
+
status: number;
|
|
72
|
+
statusText?: string;
|
|
73
|
+
text?: () => Promise<string>;
|
|
74
|
+
url?: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type BackendFederationResourceFetch = (
|
|
78
|
+
url: string,
|
|
79
|
+
init?: RequestInit,
|
|
80
|
+
) => Promise<BackendFederationResourceResponse>;
|
|
81
|
+
|
|
82
|
+
export type BackendFederationRemoteEntryFetch = BackendFederationResourceFetch;
|
|
83
|
+
|
|
84
|
+
export type BackendFederationResourcePolicy = {
|
|
85
|
+
allowInsecureHttp?: boolean;
|
|
86
|
+
fetch?: BackendFederationResourceFetch;
|
|
87
|
+
maxBytes?: number;
|
|
88
|
+
signal?: AbortSignal;
|
|
89
|
+
timeoutMs?: number;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type BackendFederationCommonJsEvaluator = (
|
|
93
|
+
source: string,
|
|
94
|
+
context: { remote: BackendFederationRemoteEntry },
|
|
95
|
+
) => unknown;
|
|
96
|
+
|
|
97
|
+
export type BackendFederationRemoteEntryPolicy =
|
|
98
|
+
BackendFederationResourcePolicy & {
|
|
99
|
+
evaluateCommonJs?: BackendFederationCommonJsEvaluator;
|
|
100
|
+
expected?: BackendFederationRemoteEntryExpectation;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type LoadVerifiedBackendFederationEntryOptions =
|
|
104
|
+
BackendFederationRemoteEntryPolicy & {
|
|
105
|
+
remote: BackendFederationRemoteEntry;
|
|
106
|
+
verification?: BackendFederationRemoteEntryVerification;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type LoadBoundedBackendFederationResourceOptions =
|
|
110
|
+
BackendFederationResourcePolicy & {
|
|
111
|
+
kind?: 'entry' | 'manifest';
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
115
|
+
typeof value === 'object' && value !== null;
|
|
116
|
+
|
|
117
|
+
const recordField = (value: unknown, key: string) => {
|
|
118
|
+
if (!isRecord(value)) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
const field = value[key];
|
|
122
|
+
return isRecord(field) ? field : undefined;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const stringField = (value: unknown) =>
|
|
126
|
+
typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
127
|
+
|
|
128
|
+
export function resolveBackendFederationRemoteEntryVerification(
|
|
129
|
+
manifest: unknown,
|
|
130
|
+
): BackendFederationRemoteEntryVerification | undefined {
|
|
131
|
+
if (!isRecord(manifest)) {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
const entry = recordField(manifest, 'entry');
|
|
135
|
+
const sha256 = entry?.sha256;
|
|
136
|
+
const byteLength = entry?.byteLength;
|
|
137
|
+
if (sha256 === undefined && byteLength === undefined) {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
const backendFederation = recordField(manifest, 'backendFederation');
|
|
141
|
+
const boundary = recordField(backendFederation, 'versionBoundary');
|
|
142
|
+
const boundaryDeliveryUnit = recordField(boundary, 'deliveryUnit');
|
|
143
|
+
const deliveryUnit = recordField(backendFederation, 'deliveryUnit');
|
|
144
|
+
const remoteName =
|
|
145
|
+
stringField(backendFederation?.name) ??
|
|
146
|
+
stringField(manifest.name) ??
|
|
147
|
+
stringField(manifest.id);
|
|
148
|
+
const entryUrl = stringField(entry?.url);
|
|
149
|
+
const containerEntry = stringField(backendFederation?.containerEntry);
|
|
150
|
+
|
|
151
|
+
if (
|
|
152
|
+
typeof sha256 !== 'string' ||
|
|
153
|
+
typeof byteLength !== 'number' ||
|
|
154
|
+
remoteName === undefined ||
|
|
155
|
+
entryUrl === undefined
|
|
156
|
+
) {
|
|
157
|
+
throw new BackendFederationRemoteEntryError(
|
|
158
|
+
'invalid_verification',
|
|
159
|
+
'[Module Federation] Backend manifest entry verification requires remote name, entry.url, sha256, and byteLength.',
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
if (
|
|
163
|
+
containerEntry !== undefined &&
|
|
164
|
+
canonicalEntryUrl(containerEntry).href !== canonicalEntryUrl(entryUrl).href
|
|
165
|
+
) {
|
|
166
|
+
throw new BackendFederationRemoteEntryError(
|
|
167
|
+
'identity_mismatch',
|
|
168
|
+
'[Module Federation] Backend manifest containerEntry must match entry.url before remote execution.',
|
|
169
|
+
{
|
|
170
|
+
details: {
|
|
171
|
+
containerEntry: redactBackendFederationUrl(containerEntry),
|
|
172
|
+
entryUrl: redactBackendFederationUrl(entryUrl),
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
const buildMarker =
|
|
178
|
+
stringField(boundaryDeliveryUnit?.buildMarker) ??
|
|
179
|
+
stringField(deliveryUnit?.buildMarker);
|
|
180
|
+
const unitId =
|
|
181
|
+
stringField(boundaryDeliveryUnit?.unitId) ??
|
|
182
|
+
stringField(deliveryUnit?.unitId);
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
byteLength,
|
|
186
|
+
entryUrl,
|
|
187
|
+
remoteName,
|
|
188
|
+
sha256,
|
|
189
|
+
...(buildMarker ? { buildMarker } : {}),
|
|
190
|
+
...(unitId ? { unitId } : {}),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const canonicalEntryUrl = (value: string) => {
|
|
195
|
+
let url: URL;
|
|
196
|
+
try {
|
|
197
|
+
url = new URL(value);
|
|
198
|
+
} catch (cause) {
|
|
199
|
+
throw new BackendFederationRemoteEntryError(
|
|
200
|
+
'invalid_verification',
|
|
201
|
+
'[Module Federation] Invalid backend federation URL.',
|
|
202
|
+
{ cause },
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
if (url.username || url.password) {
|
|
206
|
+
throw new BackendFederationRemoteEntryError(
|
|
207
|
+
'invalid_verification',
|
|
208
|
+
'[Module Federation] Backend remote entry URLs must not contain credentials.',
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
url.hash = '';
|
|
212
|
+
return url;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export function redactBackendFederationUrl(value: string) {
|
|
216
|
+
try {
|
|
217
|
+
const url = new URL(value);
|
|
218
|
+
url.username = '';
|
|
219
|
+
url.password = '';
|
|
220
|
+
url.search = '';
|
|
221
|
+
url.hash = '';
|
|
222
|
+
return url.href;
|
|
223
|
+
} catch {
|
|
224
|
+
return '[local or invalid reference]';
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const isLoopback = (hostname: string) =>
|
|
229
|
+
hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]';
|
|
230
|
+
|
|
231
|
+
const assertAllowedEntryUrl = (url: URL, allowInsecureHttp: boolean) => {
|
|
232
|
+
if (url.protocol === 'https:') {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (
|
|
236
|
+
url.protocol === 'http:' &&
|
|
237
|
+
(allowInsecureHttp || isLoopback(url.hostname))
|
|
238
|
+
) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
throw new BackendFederationRemoteEntryError(
|
|
242
|
+
'unsupported_entry',
|
|
243
|
+
`[Module Federation] Backend federation resource ${redactBackendFederationUrl(url.href)} must use HTTPS (loopback HTTP is allowed for local development).`,
|
|
244
|
+
);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const assertVerification = (
|
|
248
|
+
remote: BackendFederationRemoteEntry,
|
|
249
|
+
verification: BackendFederationRemoteEntryVerification,
|
|
250
|
+
expected: BackendFederationRemoteEntryExpectation,
|
|
251
|
+
allowInsecureHttp: boolean,
|
|
252
|
+
) => {
|
|
253
|
+
if (remote.type !== undefined && remote.type !== 'commonjs-module') {
|
|
254
|
+
throw new BackendFederationRemoteEntryError(
|
|
255
|
+
'unsupported_entry',
|
|
256
|
+
`[Module Federation] Verified backend remote ${remote.name} must be a self-contained CommonJS container.`,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
if (!/^[a-f0-9]{64}$/u.test(verification.sha256)) {
|
|
260
|
+
throw new BackendFederationRemoteEntryError(
|
|
261
|
+
'invalid_verification',
|
|
262
|
+
'[Module Federation] Backend remote entry SHA-256 must be 64 lowercase hexadecimal characters.',
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (
|
|
266
|
+
!Number.isSafeInteger(verification.byteLength) ||
|
|
267
|
+
verification.byteLength < 0
|
|
268
|
+
) {
|
|
269
|
+
throw new BackendFederationRemoteEntryError(
|
|
270
|
+
'invalid_verification',
|
|
271
|
+
'[Module Federation] Backend remote entry byteLength must be a non-negative safe integer.',
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const requestedUrl = canonicalEntryUrl(remote.entry);
|
|
276
|
+
const verifiedUrl = canonicalEntryUrl(verification.entryUrl);
|
|
277
|
+
assertAllowedEntryUrl(requestedUrl, allowInsecureHttp);
|
|
278
|
+
if (
|
|
279
|
+
remote.name !== verification.remoteName ||
|
|
280
|
+
requestedUrl.href !== verifiedUrl.href
|
|
281
|
+
) {
|
|
282
|
+
throw new BackendFederationRemoteEntryError(
|
|
283
|
+
'identity_mismatch',
|
|
284
|
+
'[Module Federation] Backend remote name or entry URL does not match its verified identity.',
|
|
285
|
+
{
|
|
286
|
+
details: {
|
|
287
|
+
requestedEntry: redactBackendFederationUrl(requestedUrl.href),
|
|
288
|
+
requestedName: remote.name,
|
|
289
|
+
verifiedEntry: redactBackendFederationUrl(verifiedUrl.href),
|
|
290
|
+
verifiedName: verification.remoteName,
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
for (const key of [
|
|
297
|
+
'buildMarker',
|
|
298
|
+
'byteLength',
|
|
299
|
+
'entryUrl',
|
|
300
|
+
'remoteName',
|
|
301
|
+
'sha256',
|
|
302
|
+
'unitId',
|
|
303
|
+
] as const) {
|
|
304
|
+
const expectedValue = expected[key];
|
|
305
|
+
if (expectedValue !== undefined && expectedValue !== verification[key]) {
|
|
306
|
+
throw new BackendFederationRemoteEntryError(
|
|
307
|
+
'identity_mismatch',
|
|
308
|
+
`[Module Federation] Backend remote entry ${key} does not match the trusted expectation.`,
|
|
309
|
+
{
|
|
310
|
+
details: {
|
|
311
|
+
expected:
|
|
312
|
+
key === 'entryUrl' && typeof expectedValue === 'string'
|
|
313
|
+
? redactBackendFederationUrl(expectedValue)
|
|
314
|
+
: expectedValue,
|
|
315
|
+
field: key,
|
|
316
|
+
received:
|
|
317
|
+
key === 'entryUrl'
|
|
318
|
+
? redactBackendFederationUrl(verification.entryUrl)
|
|
319
|
+
: verification[key],
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return requestedUrl;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const resolveTrustedVerification = (
|
|
330
|
+
verification: BackendFederationRemoteEntryVerification | undefined,
|
|
331
|
+
expected: BackendFederationRemoteEntryExpectation,
|
|
332
|
+
) => {
|
|
333
|
+
if (verification) {
|
|
334
|
+
return verification;
|
|
335
|
+
}
|
|
336
|
+
if (
|
|
337
|
+
typeof expected.byteLength === 'number' &&
|
|
338
|
+
typeof expected.entryUrl === 'string' &&
|
|
339
|
+
typeof expected.remoteName === 'string' &&
|
|
340
|
+
typeof expected.sha256 === 'string'
|
|
341
|
+
) {
|
|
342
|
+
return expected as BackendFederationRemoteEntryVerification;
|
|
343
|
+
}
|
|
344
|
+
throw new BackendFederationRemoteEntryError(
|
|
345
|
+
'invalid_verification',
|
|
346
|
+
'[Module Federation] Verified backend network loading requires trusted entryUrl, remoteName, sha256, and byteLength values.',
|
|
347
|
+
);
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
const readWithAbort = <T>(promise: Promise<T>, signal: AbortSignal) =>
|
|
351
|
+
new Promise<T>((resolve, reject) => {
|
|
352
|
+
if (signal.aborted) {
|
|
353
|
+
reject(signal.reason);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const onAbort = () => reject(signal.reason);
|
|
357
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
358
|
+
promise.then(resolve, reject).finally(() => {
|
|
359
|
+
signal.removeEventListener('abort', onAbort);
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
const parseContentLength = (value: string | null) => {
|
|
364
|
+
if (value === null || !/^\d+$/u.test(value)) {
|
|
365
|
+
return undefined;
|
|
366
|
+
}
|
|
367
|
+
const parsed = Number(value);
|
|
368
|
+
return Number.isSafeInteger(parsed) ? parsed : undefined;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
const sha256Hex = async (
|
|
372
|
+
bytes: Uint8Array<ArrayBuffer>,
|
|
373
|
+
signal: AbortSignal,
|
|
374
|
+
) => {
|
|
375
|
+
const subtle = globalThis.crypto?.subtle;
|
|
376
|
+
if (subtle === undefined) {
|
|
377
|
+
throw new BackendFederationRemoteEntryError(
|
|
378
|
+
'unsupported_entry',
|
|
379
|
+
'[Module Federation] Verified backend remote loading requires Web Crypto SHA-256 support.',
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
const digest = new Uint8Array(
|
|
383
|
+
await readWithAbort(subtle.digest('SHA-256', bytes), signal),
|
|
384
|
+
);
|
|
385
|
+
return Array.from(digest, byte => byte.toString(16).padStart(2, '0')).join(
|
|
386
|
+
'',
|
|
387
|
+
);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
export async function loadBoundedBackendFederationResource(
|
|
391
|
+
resourceUrl: string,
|
|
392
|
+
options: LoadBoundedBackendFederationResourceOptions = {},
|
|
393
|
+
) {
|
|
394
|
+
const requestedUrl = canonicalEntryUrl(resourceUrl);
|
|
395
|
+
assertAllowedEntryUrl(requestedUrl, options.allowInsecureHttp === true);
|
|
396
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_RESOURCE_BYTES;
|
|
397
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) {
|
|
398
|
+
throw new BackendFederationRemoteEntryError(
|
|
399
|
+
'invalid_verification',
|
|
400
|
+
'[Module Federation] Backend federation resource maxBytes must be a positive safe integer.',
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_ENTRY_TIMEOUT_MS;
|
|
404
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0) {
|
|
405
|
+
throw new BackendFederationRemoteEntryError(
|
|
406
|
+
'invalid_verification',
|
|
407
|
+
'[Module Federation] Backend federation resource timeoutMs must be a non-negative safe integer.',
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const controller = new AbortController();
|
|
412
|
+
let timedOut = false;
|
|
413
|
+
let callerAborted = false;
|
|
414
|
+
const onCallerAbort = () => {
|
|
415
|
+
callerAborted = true;
|
|
416
|
+
controller.abort(options.signal?.reason);
|
|
417
|
+
};
|
|
418
|
+
if (options.signal?.aborted) {
|
|
419
|
+
onCallerAbort();
|
|
420
|
+
} else {
|
|
421
|
+
options.signal?.addEventListener('abort', onCallerAbort, { once: true });
|
|
422
|
+
}
|
|
423
|
+
const timeout =
|
|
424
|
+
timeoutMs > 0
|
|
425
|
+
? setTimeout(() => {
|
|
426
|
+
timedOut = true;
|
|
427
|
+
controller.abort(
|
|
428
|
+
new Error(
|
|
429
|
+
`Backend federation ${options.kind ?? 'manifest'} timed out after ${timeoutMs}ms`,
|
|
430
|
+
),
|
|
431
|
+
);
|
|
432
|
+
}, timeoutMs)
|
|
433
|
+
: undefined;
|
|
434
|
+
const fetchResource =
|
|
435
|
+
options.fetch ??
|
|
436
|
+
(globalThis.fetch as BackendFederationResourceFetch | undefined);
|
|
437
|
+
let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;
|
|
438
|
+
const resourceKind = options.kind ?? 'manifest';
|
|
439
|
+
const cancellationError = (cause?: unknown) =>
|
|
440
|
+
new BackendFederationRemoteEntryError(
|
|
441
|
+
timedOut ? 'timeout' : 'aborted',
|
|
442
|
+
timedOut
|
|
443
|
+
? `[Module Federation] Backend federation ${resourceKind} timed out after ${timeoutMs}ms.`
|
|
444
|
+
: `[Module Federation] Backend federation ${resourceKind} loading was aborted.`,
|
|
445
|
+
{ cause },
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
try {
|
|
449
|
+
if (controller.signal.aborted) {
|
|
450
|
+
throw cancellationError(controller.signal.reason);
|
|
451
|
+
}
|
|
452
|
+
if (typeof fetchResource !== 'function') {
|
|
453
|
+
throw new BackendFederationRemoteEntryError(
|
|
454
|
+
'fetch_failed',
|
|
455
|
+
`[Module Federation] Backend federation ${resourceKind} loading requires fetch.`,
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
let response: BackendFederationResourceResponse;
|
|
460
|
+
try {
|
|
461
|
+
response = await readWithAbort(
|
|
462
|
+
fetchResource(requestedUrl.href, {
|
|
463
|
+
cache: 'no-store',
|
|
464
|
+
redirect: 'error',
|
|
465
|
+
signal: controller.signal,
|
|
466
|
+
}),
|
|
467
|
+
controller.signal,
|
|
468
|
+
);
|
|
469
|
+
} catch (cause) {
|
|
470
|
+
if (controller.signal.aborted) {
|
|
471
|
+
throw cancellationError(cause);
|
|
472
|
+
}
|
|
473
|
+
throw new BackendFederationRemoteEntryError(
|
|
474
|
+
'fetch_failed',
|
|
475
|
+
`[Module Federation] Failed to fetch backend federation ${resourceKind}.`,
|
|
476
|
+
{ cause },
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
if (!response.ok) {
|
|
480
|
+
throw new BackendFederationRemoteEntryError(
|
|
481
|
+
'fetch_failed',
|
|
482
|
+
`[Module Federation] Backend federation ${resourceKind} returned HTTP ${response.status}.`,
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
if (response.url) {
|
|
486
|
+
const responseUrl = canonicalEntryUrl(response.url);
|
|
487
|
+
if (responseUrl.href !== requestedUrl.href) {
|
|
488
|
+
throw new BackendFederationRemoteEntryError(
|
|
489
|
+
'redirect_mismatch',
|
|
490
|
+
`[Module Federation] Backend federation ${resourceKind} redirected outside its trusted URL.`,
|
|
491
|
+
{
|
|
492
|
+
details: {
|
|
493
|
+
expected: redactBackendFederationUrl(requestedUrl.href),
|
|
494
|
+
received: redactBackendFederationUrl(responseUrl.href),
|
|
495
|
+
},
|
|
496
|
+
},
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
const contentLength = parseContentLength(
|
|
502
|
+
response.headers?.get('content-length') ?? null,
|
|
503
|
+
);
|
|
504
|
+
if (contentLength !== undefined && contentLength > maxBytes) {
|
|
505
|
+
controller.abort();
|
|
506
|
+
await response.body?.cancel().catch(() => undefined);
|
|
507
|
+
throw new BackendFederationRemoteEntryError(
|
|
508
|
+
'entry_too_large',
|
|
509
|
+
`[Module Federation] Backend federation ${resourceKind} declares ${contentLength} bytes, exceeding its ${maxBytes}-byte policy limit.`,
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const chunks: Uint8Array[] = [];
|
|
514
|
+
let byteLength = 0;
|
|
515
|
+
if (response.body) {
|
|
516
|
+
reader = response.body.getReader();
|
|
517
|
+
while (true) {
|
|
518
|
+
const result = await readWithAbort(reader.read(), controller.signal);
|
|
519
|
+
if (result.done) {
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
byteLength += result.value.byteLength;
|
|
523
|
+
if (byteLength > maxBytes) {
|
|
524
|
+
throw new BackendFederationRemoteEntryError(
|
|
525
|
+
'entry_too_large',
|
|
526
|
+
`[Module Federation] Backend federation ${resourceKind} exceeded its ${maxBytes}-byte limit while streaming.`,
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
chunks.push(result.value);
|
|
530
|
+
}
|
|
531
|
+
} else if (response.text) {
|
|
532
|
+
const bytes = new TextEncoder().encode(
|
|
533
|
+
await readWithAbort(response.text(), controller.signal),
|
|
534
|
+
);
|
|
535
|
+
if (bytes.byteLength > maxBytes) {
|
|
536
|
+
throw new BackendFederationRemoteEntryError(
|
|
537
|
+
'entry_too_large',
|
|
538
|
+
`[Module Federation] Backend federation ${resourceKind} exceeded its ${maxBytes}-byte limit.`,
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
chunks.push(bytes);
|
|
542
|
+
byteLength = bytes.byteLength;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const bytes = new Uint8Array(byteLength);
|
|
546
|
+
let offset = 0;
|
|
547
|
+
for (const chunk of chunks) {
|
|
548
|
+
bytes.set(chunk, offset);
|
|
549
|
+
offset += chunk.byteLength;
|
|
550
|
+
}
|
|
551
|
+
if (controller.signal.aborted) {
|
|
552
|
+
throw cancellationError(controller.signal.reason);
|
|
553
|
+
}
|
|
554
|
+
return bytes;
|
|
555
|
+
} catch (cause) {
|
|
556
|
+
if (!controller.signal.aborted) {
|
|
557
|
+
controller.abort(cause);
|
|
558
|
+
}
|
|
559
|
+
await reader?.cancel(cause).catch(() => undefined);
|
|
560
|
+
if (cause instanceof BackendFederationRemoteEntryError) {
|
|
561
|
+
throw cause;
|
|
562
|
+
}
|
|
563
|
+
if (timedOut || callerAborted) {
|
|
564
|
+
throw cancellationError(cause);
|
|
565
|
+
}
|
|
566
|
+
throw new BackendFederationRemoteEntryError(
|
|
567
|
+
'fetch_failed',
|
|
568
|
+
`[Module Federation] Backend federation ${resourceKind} loading failed.`,
|
|
569
|
+
{ cause },
|
|
570
|
+
);
|
|
571
|
+
} finally {
|
|
572
|
+
if (timeout) {
|
|
573
|
+
clearTimeout(timeout);
|
|
574
|
+
}
|
|
575
|
+
options.signal?.removeEventListener('abort', onCallerAbort);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export const evaluateBackendFederationCommonJsEntry = (
|
|
580
|
+
remote: BackendFederationRemoteEntry,
|
|
581
|
+
bytes: Uint8Array,
|
|
582
|
+
evaluator?: BackendFederationCommonJsEvaluator,
|
|
583
|
+
) => {
|
|
584
|
+
let source: string;
|
|
585
|
+
try {
|
|
586
|
+
source = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
587
|
+
} catch (cause) {
|
|
588
|
+
throw new BackendFederationRemoteEntryError(
|
|
589
|
+
'integrity_mismatch',
|
|
590
|
+
`[Module Federation] Backend remote ${remote.name} is not valid UTF-8 JavaScript.`,
|
|
591
|
+
{ cause },
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if (evaluator === undefined) {
|
|
596
|
+
throw new BackendFederationRemoteEntryError(
|
|
597
|
+
'unsupported_entry',
|
|
598
|
+
`[Module Federation] Backend remote ${remote.name} requires an explicit runtime evaluator. Node callers should use the Node security subpath; edge callers should use a service binding or native module provider.`,
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
const evaluated = evaluator(source, { remote });
|
|
602
|
+
const defaultExport =
|
|
603
|
+
typeof evaluated === 'object' &&
|
|
604
|
+
evaluated !== null &&
|
|
605
|
+
'default' in evaluated
|
|
606
|
+
? evaluated.default
|
|
607
|
+
: undefined;
|
|
608
|
+
const entry = defaultExport ?? evaluated;
|
|
609
|
+
if (
|
|
610
|
+
typeof entry !== 'object' ||
|
|
611
|
+
entry === null ||
|
|
612
|
+
typeof (entry as Partial<BackendFederationEntryExports>).get !== 'function'
|
|
613
|
+
) {
|
|
614
|
+
throw new BackendFederationRemoteEntryError(
|
|
615
|
+
'fetch_failed',
|
|
616
|
+
`[Module Federation] Backend remote ${remote.name} did not evaluate to a container entry.`,
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
return entry as BackendFederationEntryExports;
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
export async function loadVerifiedBackendFederationEntry(
|
|
623
|
+
options: LoadVerifiedBackendFederationEntryOptions,
|
|
624
|
+
): Promise<BackendFederationEntryExports> {
|
|
625
|
+
const verification = resolveTrustedVerification(
|
|
626
|
+
options.verification,
|
|
627
|
+
options.expected ?? {},
|
|
628
|
+
);
|
|
629
|
+
const requestedUrl = assertVerification(
|
|
630
|
+
options.remote,
|
|
631
|
+
verification,
|
|
632
|
+
options.expected ?? {},
|
|
633
|
+
options.allowInsecureHttp === true,
|
|
634
|
+
);
|
|
635
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_ENTRY_BYTES;
|
|
636
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) {
|
|
637
|
+
throw new BackendFederationRemoteEntryError(
|
|
638
|
+
'invalid_verification',
|
|
639
|
+
'[Module Federation] Backend remote entry maxBytes must be a positive safe integer.',
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
if (verification.byteLength > maxBytes) {
|
|
643
|
+
throw new BackendFederationRemoteEntryError(
|
|
644
|
+
'entry_too_large',
|
|
645
|
+
`[Module Federation] Backend remote entry exceeds the ${maxBytes}-byte policy limit.`,
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_ENTRY_TIMEOUT_MS;
|
|
650
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0) {
|
|
651
|
+
throw new BackendFederationRemoteEntryError(
|
|
652
|
+
'invalid_verification',
|
|
653
|
+
'[Module Federation] Backend remote entry timeoutMs must be a non-negative safe integer.',
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
const controller = new AbortController();
|
|
657
|
+
let timedOut = false;
|
|
658
|
+
let callerAborted = false;
|
|
659
|
+
const onCallerAbort = () => {
|
|
660
|
+
callerAborted = true;
|
|
661
|
+
controller.abort(options.signal?.reason);
|
|
662
|
+
};
|
|
663
|
+
if (options.signal?.aborted) {
|
|
664
|
+
onCallerAbort();
|
|
665
|
+
} else {
|
|
666
|
+
options.signal?.addEventListener('abort', onCallerAbort, { once: true });
|
|
667
|
+
}
|
|
668
|
+
const timeout =
|
|
669
|
+
timeoutMs > 0
|
|
670
|
+
? setTimeout(() => {
|
|
671
|
+
timedOut = true;
|
|
672
|
+
controller.abort(
|
|
673
|
+
new Error(`Backend remote entry timed out after ${timeoutMs}ms`),
|
|
674
|
+
);
|
|
675
|
+
}, timeoutMs)
|
|
676
|
+
: undefined;
|
|
677
|
+
const fetchEntry = options.fetch ?? globalThis.fetch;
|
|
678
|
+
let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;
|
|
679
|
+
|
|
680
|
+
const cancellationError = (cause?: unknown) =>
|
|
681
|
+
new BackendFederationRemoteEntryError(
|
|
682
|
+
timedOut ? 'timeout' : 'aborted',
|
|
683
|
+
timedOut
|
|
684
|
+
? `[Module Federation] Backend remote ${options.remote.name} timed out after ${timeoutMs}ms.`
|
|
685
|
+
: `[Module Federation] Backend remote ${options.remote.name} loading was aborted.`,
|
|
686
|
+
{ cause },
|
|
687
|
+
);
|
|
688
|
+
|
|
689
|
+
try {
|
|
690
|
+
if (controller.signal.aborted) {
|
|
691
|
+
throw cancellationError(controller.signal.reason);
|
|
692
|
+
}
|
|
693
|
+
if (typeof fetchEntry !== 'function') {
|
|
694
|
+
throw new BackendFederationRemoteEntryError(
|
|
695
|
+
'fetch_failed',
|
|
696
|
+
'[Module Federation] Backend remote entry loading requires fetch.',
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
let response: BackendFederationResourceResponse;
|
|
701
|
+
try {
|
|
702
|
+
response = await readWithAbort(
|
|
703
|
+
fetchEntry(requestedUrl.href, {
|
|
704
|
+
cache: 'no-store',
|
|
705
|
+
redirect: 'error',
|
|
706
|
+
signal: controller.signal,
|
|
707
|
+
}),
|
|
708
|
+
controller.signal,
|
|
709
|
+
);
|
|
710
|
+
} catch (cause) {
|
|
711
|
+
if (controller.signal.aborted) {
|
|
712
|
+
throw cancellationError(cause);
|
|
713
|
+
}
|
|
714
|
+
throw new BackendFederationRemoteEntryError(
|
|
715
|
+
'fetch_failed',
|
|
716
|
+
`[Module Federation] Failed to fetch backend remote ${options.remote.name}.`,
|
|
717
|
+
{ cause },
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
if (!response.ok) {
|
|
721
|
+
throw new BackendFederationRemoteEntryError(
|
|
722
|
+
'fetch_failed',
|
|
723
|
+
`[Module Federation] Backend remote ${options.remote.name} returned HTTP ${response.status}.`,
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
if (response.url) {
|
|
727
|
+
const responseUrl = canonicalEntryUrl(response.url);
|
|
728
|
+
if (responseUrl.href !== requestedUrl.href) {
|
|
729
|
+
throw new BackendFederationRemoteEntryError(
|
|
730
|
+
'redirect_mismatch',
|
|
731
|
+
`[Module Federation] Backend remote ${options.remote.name} redirected outside its verified entry URL.`,
|
|
732
|
+
{
|
|
733
|
+
details: {
|
|
734
|
+
expected: redactBackendFederationUrl(requestedUrl.href),
|
|
735
|
+
received: redactBackendFederationUrl(responseUrl.href),
|
|
736
|
+
},
|
|
737
|
+
},
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
const contentLength = parseContentLength(
|
|
743
|
+
response.headers?.get('content-length') ?? null,
|
|
744
|
+
);
|
|
745
|
+
const byteLimit = Math.min(maxBytes, verification.byteLength);
|
|
746
|
+
if (contentLength !== undefined && contentLength > maxBytes) {
|
|
747
|
+
controller.abort();
|
|
748
|
+
await response.body?.cancel().catch(() => undefined);
|
|
749
|
+
throw new BackendFederationRemoteEntryError(
|
|
750
|
+
'entry_too_large',
|
|
751
|
+
`[Module Federation] Backend remote ${options.remote.name} declares ${contentLength} bytes, exceeding its ${maxBytes}-byte policy limit.`,
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
reader = response.body?.getReader();
|
|
756
|
+
const bytes = new Uint8Array(verification.byteLength);
|
|
757
|
+
let byteLength = 0;
|
|
758
|
+
if (reader) {
|
|
759
|
+
while (true) {
|
|
760
|
+
const result = await readWithAbort(reader.read(), controller.signal);
|
|
761
|
+
if (result.done) {
|
|
762
|
+
break;
|
|
763
|
+
}
|
|
764
|
+
const nextByteLength = byteLength + result.value.byteLength;
|
|
765
|
+
if (nextByteLength > byteLimit) {
|
|
766
|
+
throw new BackendFederationRemoteEntryError(
|
|
767
|
+
'entry_too_large',
|
|
768
|
+
`[Module Federation] Backend remote ${options.remote.name} exceeded its ${byteLimit}-byte limit while streaming.`,
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
bytes.set(result.value, byteLength);
|
|
772
|
+
byteLength = nextByteLength;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
if (byteLength !== verification.byteLength) {
|
|
777
|
+
throw new BackendFederationRemoteEntryError(
|
|
778
|
+
'byte_length_mismatch',
|
|
779
|
+
`[Module Federation] Backend remote ${options.remote.name} byte length mismatch.`,
|
|
780
|
+
{
|
|
781
|
+
details: {
|
|
782
|
+
expected: verification.byteLength,
|
|
783
|
+
received: byteLength,
|
|
784
|
+
},
|
|
785
|
+
},
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
const actualDigest = await sha256Hex(bytes, controller.signal);
|
|
789
|
+
if (controller.signal.aborted) {
|
|
790
|
+
throw cancellationError(controller.signal.reason);
|
|
791
|
+
}
|
|
792
|
+
if (actualDigest !== verification.sha256) {
|
|
793
|
+
throw new BackendFederationRemoteEntryError(
|
|
794
|
+
'integrity_mismatch',
|
|
795
|
+
`[Module Federation] Backend remote ${options.remote.name} SHA-256 mismatch.`,
|
|
796
|
+
{
|
|
797
|
+
details: {
|
|
798
|
+
expected: verification.sha256,
|
|
799
|
+
received: actualDigest,
|
|
800
|
+
},
|
|
801
|
+
},
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
return evaluateBackendFederationCommonJsEntry(
|
|
806
|
+
options.remote,
|
|
807
|
+
bytes,
|
|
808
|
+
options.evaluateCommonJs,
|
|
809
|
+
);
|
|
810
|
+
} catch (cause) {
|
|
811
|
+
if (!controller.signal.aborted) {
|
|
812
|
+
controller.abort(cause);
|
|
813
|
+
}
|
|
814
|
+
await reader?.cancel(cause).catch(() => undefined);
|
|
815
|
+
if (
|
|
816
|
+
cause instanceof BackendFederationRemoteEntryError &&
|
|
817
|
+
!(cause.code === 'aborted' && timedOut)
|
|
818
|
+
) {
|
|
819
|
+
throw cause;
|
|
820
|
+
}
|
|
821
|
+
if (controller.signal.aborted && (timedOut || callerAborted)) {
|
|
822
|
+
throw cancellationError(cause);
|
|
823
|
+
}
|
|
824
|
+
throw cause;
|
|
825
|
+
} finally {
|
|
826
|
+
if (timeout) {
|
|
827
|
+
clearTimeout(timeout);
|
|
828
|
+
}
|
|
829
|
+
options.signal?.removeEventListener('abort', onCallerAbort);
|
|
830
|
+
}
|
|
831
|
+
}
|