@bleedingdev/modern-js-server-runtime-extensions 3.9.0-ultramodern.9 → 3.9.3-ultramodern.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +3 -1
  2. package/dist/cjs/backend-federation-security/index.js +73 -152
  3. package/dist/cjs/bff-policy/index.js +7 -0
  4. package/dist/cjs/bff-policy/node.js +20 -4
  5. package/dist/cjs/bff-policy/operationContracts.js +150 -135
  6. package/dist/cjs/bff-policy/operationIdentity.js +81 -0
  7. package/dist/cjs/bff-policy/producer.js +79 -0
  8. package/dist/cjs/localisedLoader.js +65 -0
  9. package/dist/cjs/localisedLoaderPlugin.js +2 -2
  10. package/dist/cjs/module-federation-css/remote.js +2 -1
  11. package/dist/cjs/static-serving/staticModuleFederation.js +49 -12
  12. package/dist/esm/backend-federation-security/index.mjs +73 -152
  13. package/dist/esm/bff-policy/index.mjs +1 -0
  14. package/dist/esm/bff-policy/operationIdentity.mjs +30 -0
  15. package/dist/esm/bff-policy/producer.mjs +31 -0
  16. package/dist/esm/localisedLoader.mjs +24 -0
  17. package/dist/esm/localisedLoaderPlugin.mjs +2 -2
  18. package/dist/esm/module-federation-css/remote.mjs +2 -1
  19. package/dist/esm-node/backend-federation-security/index.mjs +73 -152
  20. package/dist/esm-node/bff-policy/index.mjs +1 -0
  21. package/dist/esm-node/bff-policy/node.mjs +1 -0
  22. package/dist/esm-node/bff-policy/operationContracts.mjs +5 -27
  23. package/dist/esm-node/bff-policy/operationIdentity.mjs +31 -0
  24. package/dist/esm-node/bff-policy/producer.mjs +32 -0
  25. package/dist/esm-node/localisedLoader.mjs +25 -0
  26. package/dist/esm-node/localisedLoaderPlugin.mjs +2 -2
  27. package/dist/esm-node/module-federation-css/remote.mjs +2 -1
  28. package/dist/esm-node/static-serving/staticModuleFederation.mjs +49 -12
  29. package/dist/types/backend-federation-security/node.d.ts +1 -1
  30. package/dist/types/bff-policy/index.d.ts +1 -0
  31. package/dist/types/bff-policy/node.d.ts +1 -0
  32. package/dist/types/bff-policy/operationContracts.d.ts +2 -41
  33. package/dist/types/bff-policy/operationIdentity.d.ts +34 -0
  34. package/dist/types/bff-policy/producer.d.ts +10 -0
  35. package/dist/types/localisedLoader.d.ts +15 -0
  36. package/dist/types/module-federation-css/remote.d.ts +2 -0
  37. package/dist/types/serverConfig.d.ts +4 -2
  38. package/dist/types/telemetry/runtimeEndpoints.d.ts +2 -13
  39. package/dist/types-esm/backend-federation-security/node.d.mts +1 -1
  40. package/dist/types-esm/bff-policy/index.d.mts +1 -0
  41. package/dist/types-esm/bff-policy/node.d.mts +1 -0
  42. package/dist/types-esm/bff-policy/operationContracts.d.mts +2 -41
  43. package/dist/types-esm/bff-policy/operationIdentity.d.mts +34 -0
  44. package/dist/types-esm/bff-policy/producer.d.mts +10 -0
  45. package/dist/types-esm/localisedLoader.d.mts +15 -0
  46. package/dist/types-esm/module-federation-css/remote.d.mts +2 -0
  47. package/dist/types-esm/serverConfig.d.mts +4 -2
  48. package/dist/types-esm/telemetry/runtimeEndpoints.d.mts +2 -13
  49. package/package.json +48 -20
  50. package/src/backend-federation-security/index.ts +151 -318
  51. package/src/backend-federation-security/node.ts +24 -22
  52. package/src/bff-policy/index.ts +1 -0
  53. package/src/bff-policy/node.ts +1 -0
  54. package/src/bff-policy/operationContracts.ts +13 -86
  55. package/src/bff-policy/operationIdentity.ts +90 -0
  56. package/src/bff-policy/producer.ts +40 -0
  57. package/src/contract-gate-snapshot-store/resolve.ts +0 -1
  58. package/src/localisedLoader.ts +50 -0
  59. package/src/localisedLoaderPlugin.ts +6 -7
  60. package/src/module-federation-css/remote.ts +3 -1
  61. package/src/serverConfig.ts +7 -0
  62. package/src/static-serving/staticModuleFederation.ts +127 -22
  63. package/src/telemetry/runtimeEndpoints.ts +2 -2
  64. package/rslib.config.mts +0 -38
  65. package/rstest.config.mts +0 -18
  66. package/tests/backendFederationSecurity.test.ts +0 -416
  67. package/tests/bff-policy/crossProjectPolicy.matrix.test.ts +0 -450
  68. package/tests/bff-policy/crossProjectPolicy.test.ts +0 -197
  69. package/tests/bff-policy/operationContracts.test.ts +0 -221
  70. package/tests/bff-policy/optionalZodPeer.test.ts +0 -30
  71. package/tests/bff-policy/resolveCrossProjectPolicy.test.ts +0 -76
  72. package/tests/contractGateSnapshotObserver.test.ts +0 -347
  73. package/tests/contractGateSnapshotStore.test.ts +0 -225
  74. package/tests/env.test.ts +0 -54
  75. package/tests/helpers.ts +0 -20
  76. package/tests/localisedLoader.test.ts +0 -120
  77. package/tests/mfCache.test.ts +0 -63
  78. package/tests/moduleFederationCss.test.ts +0 -348
  79. package/tests/nativeErrorResponse.test.ts +0 -118
  80. package/tests/nativeServerAssembly.test.ts +0 -385
  81. package/tests/runtimeLifecycle.test.ts +0 -159
  82. package/tests/static-serving/ordering.test.ts +0 -214
  83. package/tests/static-serving/static.test.ts +0 -411
  84. package/tests/telemetry.test.ts +0 -248
  85. package/tests/telemetryHealthMonitor.test.ts +0 -183
  86. package/tests/telemetryHealthObservation.test.ts +0 -302
  87. package/tests/telemetryLifecycle.test.ts +0 -123
  88. package/tests/telemetryRegistryQueueMatrix.test.ts +0 -130
  89. package/tests/telemetryTraceparent.test.ts +0 -167
  90. package/tests/tsconfig.json +0 -11
  91. package/tsconfig.json +0 -10
@@ -142,97 +142,85 @@ const sha256Hex = async (bytes, signal)=>{
142
142
  const digest = new Uint8Array(await readWithAbort(subtle.digest('SHA-256', bytes), signal));
143
143
  return Array.from(digest, (byte)=>byte.toString(16).padStart(2, '0')).join('');
144
144
  };
145
- async function loadBoundedBackendFederationResource(resourceUrl, options = {}) {
146
- const requestedUrl = canonicalEntryUrl(resourceUrl);
147
- assertAllowedEntryUrl(requestedUrl, true === options.allowInsecureHttp);
148
- const maxBytes = options.maxBytes ?? DEFAULT_MAX_RESOURCE_BYTES;
149
- if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend federation resource maxBytes must be a positive safe integer.');
145
+ async function acquireBackendFederationResource(requestedUrl, options, policy) {
146
+ const { label, maxBytes, exactByteLength } = policy;
150
147
  const timeoutMs = options.timeoutMs ?? DEFAULT_ENTRY_TIMEOUT_MS;
151
- if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend federation resource timeoutMs must be a non-negative safe integer.');
148
+ if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0 || !Number.isSafeInteger(timeoutMs) || timeoutMs < 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Resource maxBytes must be a positive safe integer and timeoutMs a non-negative safe integer.');
149
+ if (void 0 !== exactByteLength && exactByteLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] ${label} exceeds the ${maxBytes}-byte policy limit.`);
152
150
  const controller = new AbortController();
153
151
  let timedOut = false;
154
- let callerAborted = false;
155
- const onCallerAbort = ()=>{
156
- callerAborted = true;
157
- controller.abort(options.signal?.reason);
158
- };
152
+ const onCallerAbort = ()=>controller.abort(options.signal?.reason);
159
153
  if (options.signal?.aborted) onCallerAbort();
160
154
  else options.signal?.addEventListener('abort', onCallerAbort, {
161
155
  once: true
162
156
  });
163
157
  const timeout = timeoutMs > 0 ? setTimeout(()=>{
164
158
  timedOut = true;
165
- controller.abort(new Error(`Backend federation ${options.kind ?? 'manifest'} timed out after ${timeoutMs}ms`));
159
+ controller.abort(new Error(`${label} timed out after ${timeoutMs}ms`));
166
160
  }, timeoutMs) : void 0;
167
- const fetchResource = options.fetch ?? globalThis.fetch;
168
161
  let reader;
169
- const resourceKind = options.kind ?? 'manifest';
170
- const cancellationError = (cause)=>new BackendFederationRemoteEntryError(timedOut ? 'timeout' : 'aborted', timedOut ? `[Module Federation] Backend federation ${resourceKind} timed out after ${timeoutMs}ms.` : `[Module Federation] Backend federation ${resourceKind} loading was aborted.`, {
171
- cause
172
- });
162
+ let response;
173
163
  try {
174
- if (controller.signal.aborted) throw cancellationError(controller.signal.reason);
175
- if ('function' != typeof fetchResource) throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend federation ${resourceKind} loading requires fetch.`);
176
- let response;
177
- try {
178
- response = await readWithAbort(fetchResource(requestedUrl.href, {
179
- cache: 'no-store',
180
- redirect: 'error',
181
- signal: controller.signal
182
- }), controller.signal);
183
- } catch (cause) {
184
- if (controller.signal.aborted) throw cancellationError(cause);
185
- throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Failed to fetch backend federation ${resourceKind}.`, {
186
- cause
187
- });
188
- }
189
- if (!response.ok) throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend federation ${resourceKind} returned HTTP ${response.status}.`);
190
- if (response.url) {
191
- const responseUrl = canonicalEntryUrl(response.url);
192
- if (responseUrl.href !== requestedUrl.href) throw new BackendFederationRemoteEntryError('redirect_mismatch', `[Module Federation] Backend federation ${resourceKind} redirected outside its trusted URL.`, {
193
- details: {
194
- expected: redactBackendFederationUrl(requestedUrl.href),
195
- received: redactBackendFederationUrl(responseUrl.href)
196
- }
197
- });
198
- }
164
+ const fetchResource = options.fetch ?? globalThis.fetch;
165
+ if (controller.signal.aborted) throw controller.signal.reason;
166
+ if ('function' != typeof fetchResource) throw new Error('Loading requires fetch.');
167
+ response = await readWithAbort(fetchResource(requestedUrl.href, {
168
+ cache: 'no-store',
169
+ redirect: 'error',
170
+ signal: controller.signal
171
+ }), controller.signal);
172
+ if (!response.ok) throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] ${label} returned HTTP ${response.status}.`);
173
+ if (response.url && canonicalEntryUrl(response.url).href !== requestedUrl.href) throw new BackendFederationRemoteEntryError('redirect_mismatch', `[Module Federation] ${label} redirected outside its trusted URL.`, {
174
+ details: {
175
+ expected: redactBackendFederationUrl(requestedUrl.href),
176
+ received: redactBackendFederationUrl(response.url)
177
+ }
178
+ });
199
179
  const contentLength = parseContentLength(response.headers?.get('content-length') ?? null);
200
- if (void 0 !== contentLength && contentLength > maxBytes) {
201
- controller.abort();
202
- await response.body?.cancel().catch(()=>void 0);
203
- throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend federation ${resourceKind} declares ${contentLength} bytes, exceeding its ${maxBytes}-byte policy limit.`);
204
- }
180
+ const byteLimit = exactByteLength ?? maxBytes;
181
+ if (void 0 !== contentLength && contentLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] ${label} declares ${contentLength} bytes, exceeding its ${maxBytes}-byte policy limit.`);
182
+ const exactBytes = void 0 === exactByteLength ? void 0 : new Uint8Array(exactByteLength);
205
183
  const chunks = [];
206
184
  let byteLength = 0;
185
+ const append = (chunk)=>{
186
+ if (byteLength + chunk.byteLength > byteLimit) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] ${label} exceeded its ${byteLimit}-byte limit while streaming.`);
187
+ if (exactBytes) exactBytes.set(chunk, byteLength);
188
+ else chunks.push(chunk);
189
+ byteLength += chunk.byteLength;
190
+ };
207
191
  if (response.body) {
208
192
  reader = response.body.getReader();
209
193
  while(true){
210
194
  const result = await readWithAbort(reader.read(), controller.signal);
211
195
  if (result.done) break;
212
- byteLength += result.value.byteLength;
213
- if (byteLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend federation ${resourceKind} exceeded its ${maxBytes}-byte limit while streaming.`);
214
- chunks.push(result.value);
196
+ append(result.value);
215
197
  }
216
- } else if (response.text) {
217
- const bytes = new TextEncoder().encode(await readWithAbort(response.text(), controller.signal));
218
- if (bytes.byteLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend federation ${resourceKind} exceeded its ${maxBytes}-byte limit.`);
219
- chunks.push(bytes);
220
- byteLength = bytes.byteLength;
221
- }
222
- const bytes = new Uint8Array(byteLength);
198
+ } else if (void 0 === exactByteLength && response.text) append(new TextEncoder().encode(await readWithAbort(response.text(), controller.signal)));
199
+ if (void 0 !== exactByteLength && byteLength !== exactByteLength) throw new BackendFederationRemoteEntryError('byte_length_mismatch', `[Module Federation] ${label} byte length mismatch.`, {
200
+ details: {
201
+ expected: exactByteLength,
202
+ received: byteLength
203
+ }
204
+ });
205
+ const bytes = exactBytes ?? new Uint8Array(byteLength);
223
206
  let offset = 0;
224
207
  for (const chunk of chunks){
225
208
  bytes.set(chunk, offset);
226
209
  offset += chunk.byteLength;
227
210
  }
228
- if (controller.signal.aborted) throw cancellationError(controller.signal.reason);
211
+ if (controller.signal.aborted) throw controller.signal.reason;
212
+ if (policy.verify) await readWithAbort(policy.verify(bytes, controller.signal), controller.signal);
229
213
  return bytes;
230
214
  } catch (cause) {
231
- if (!controller.signal.aborted) controller.abort(cause);
232
- await reader?.cancel(cause).catch(()=>void 0);
215
+ const cancelled = controller.signal.aborted;
216
+ controller.abort(cause);
217
+ if (reader) reader.cancel(cause).catch(()=>void 0);
218
+ else if (response?.body) response.body.cancel(cause).catch(()=>void 0);
219
+ if (cancelled) throw new BackendFederationRemoteEntryError(timedOut ? 'timeout' : 'aborted', timedOut ? `[Module Federation] ${label} timed out after ${timeoutMs}ms.` : `[Module Federation] ${label} loading was aborted.`, {
220
+ cause
221
+ });
233
222
  if (cause instanceof BackendFederationRemoteEntryError) throw cause;
234
- if (timedOut || callerAborted) throw cancellationError(cause);
235
- throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend federation ${resourceKind} loading failed.`, {
223
+ throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] ${label} loading failed.`, {
236
224
  cause
237
225
  });
238
226
  } finally{
@@ -240,6 +228,14 @@ async function loadBoundedBackendFederationResource(resourceUrl, options = {}) {
240
228
  options.signal?.removeEventListener('abort', onCallerAbort);
241
229
  }
242
230
  }
231
+ async function loadBoundedBackendFederationResource(resourceUrl, options = {}) {
232
+ const requestedUrl = canonicalEntryUrl(resourceUrl);
233
+ assertAllowedEntryUrl(requestedUrl, true === options.allowInsecureHttp);
234
+ return acquireBackendFederationResource(requestedUrl, options, {
235
+ label: `Backend federation ${options.kind ?? 'manifest'}`,
236
+ maxBytes: options.maxBytes ?? DEFAULT_MAX_RESOURCE_BYTES
237
+ });
238
+ }
243
239
  const evaluateBackendFederationCommonJsEntry = (remote, bytes, evaluator)=>{
244
240
  let source;
245
241
  try {
@@ -263,99 +259,24 @@ const evaluateBackendFederationCommonJsEntry = (remote, bytes, evaluator)=>{
263
259
  async function loadVerifiedBackendFederationEntry(options) {
264
260
  const verification = resolveTrustedVerification(options.verification, options.expected ?? {});
265
261
  const requestedUrl = assertVerification(options.remote, verification, options.expected ?? {}, true === options.allowInsecureHttp);
266
- const maxBytes = options.maxBytes ?? DEFAULT_MAX_ENTRY_BYTES;
267
- if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend remote entry maxBytes must be a positive safe integer.');
268
- if (verification.byteLength > maxBytes) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend remote entry exceeds the ${maxBytes}-byte policy limit.`);
269
- const timeoutMs = options.timeoutMs ?? DEFAULT_ENTRY_TIMEOUT_MS;
270
- if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0) throw new BackendFederationRemoteEntryError('invalid_verification', '[Module Federation] Backend remote entry timeoutMs must be a non-negative safe integer.');
271
- const controller = new AbortController();
272
- let timedOut = false;
273
- let callerAborted = false;
274
- const onCallerAbort = ()=>{
275
- callerAborted = true;
276
- controller.abort(options.signal?.reason);
277
- };
278
- if (options.signal?.aborted) onCallerAbort();
279
- else options.signal?.addEventListener('abort', onCallerAbort, {
280
- once: true
281
- });
282
- const timeout = timeoutMs > 0 ? setTimeout(()=>{
283
- timedOut = true;
284
- controller.abort(new Error(`Backend remote entry timed out after ${timeoutMs}ms`));
285
- }, timeoutMs) : void 0;
286
- const fetchEntry = options.fetch ?? globalThis.fetch;
287
- let reader;
288
- const cancellationError = (cause)=>new BackendFederationRemoteEntryError(timedOut ? 'timeout' : 'aborted', timedOut ? `[Module Federation] Backend remote ${options.remote.name} timed out after ${timeoutMs}ms.` : `[Module Federation] Backend remote ${options.remote.name} loading was aborted.`, {
289
- cause
290
- });
291
- try {
292
- if (controller.signal.aborted) throw cancellationError(controller.signal.reason);
293
- if ('function' != typeof fetchEntry) throw new BackendFederationRemoteEntryError('fetch_failed', '[Module Federation] Backend remote entry loading requires fetch.');
294
- let response;
295
- try {
296
- response = await readWithAbort(fetchEntry(requestedUrl.href, {
297
- cache: 'no-store',
298
- redirect: 'error',
299
- signal: controller.signal
300
- }), controller.signal);
301
- } catch (cause) {
302
- if (controller.signal.aborted) throw cancellationError(cause);
303
- throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Failed to fetch backend remote ${options.remote.name}.`, {
304
- cause
305
- });
306
- }
307
- if (!response.ok) throw new BackendFederationRemoteEntryError('fetch_failed', `[Module Federation] Backend remote ${options.remote.name} returned HTTP ${response.status}.`);
308
- if (response.url) {
309
- const responseUrl = canonicalEntryUrl(response.url);
310
- if (responseUrl.href !== requestedUrl.href) throw new BackendFederationRemoteEntryError('redirect_mismatch', `[Module Federation] Backend remote ${options.remote.name} redirected outside its verified entry URL.`, {
262
+ const bytes = await acquireBackendFederationResource(requestedUrl, options, {
263
+ label: `Backend remote ${options.remote.name}`,
264
+ maxBytes: options.maxBytes ?? DEFAULT_MAX_ENTRY_BYTES,
265
+ exactByteLength: verification.byteLength,
266
+ async verify (bytes, signal) {
267
+ const actualDigest = await sha256Hex(bytes, signal);
268
+ if (signal.aborted) throw signal.reason;
269
+ if (actualDigest !== verification.sha256) throw new BackendFederationRemoteEntryError('integrity_mismatch', `[Module Federation] Backend remote ${options.remote.name} SHA-256 mismatch.`, {
311
270
  details: {
312
- expected: redactBackendFederationUrl(requestedUrl.href),
313
- received: redactBackendFederationUrl(responseUrl.href)
271
+ expected: verification.sha256,
272
+ received: actualDigest
314
273
  }
315
274
  });
316
275
  }
317
- const contentLength = parseContentLength(response.headers?.get('content-length') ?? null);
318
- const byteLimit = Math.min(maxBytes, verification.byteLength);
319
- if (void 0 !== contentLength && contentLength > maxBytes) {
320
- controller.abort();
321
- await response.body?.cancel().catch(()=>void 0);
322
- throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend remote ${options.remote.name} declares ${contentLength} bytes, exceeding its ${maxBytes}-byte policy limit.`);
323
- }
324
- reader = response.body?.getReader();
325
- const bytes = new Uint8Array(verification.byteLength);
326
- let byteLength = 0;
327
- if (reader) while(true){
328
- const result = await readWithAbort(reader.read(), controller.signal);
329
- if (result.done) break;
330
- const nextByteLength = byteLength + result.value.byteLength;
331
- if (nextByteLength > byteLimit) throw new BackendFederationRemoteEntryError('entry_too_large', `[Module Federation] Backend remote ${options.remote.name} exceeded its ${byteLimit}-byte limit while streaming.`);
332
- bytes.set(result.value, byteLength);
333
- byteLength = nextByteLength;
334
- }
335
- if (byteLength !== verification.byteLength) throw new BackendFederationRemoteEntryError('byte_length_mismatch', `[Module Federation] Backend remote ${options.remote.name} byte length mismatch.`, {
336
- details: {
337
- expected: verification.byteLength,
338
- received: byteLength
339
- }
340
- });
341
- const actualDigest = await sha256Hex(bytes, controller.signal);
342
- if (controller.signal.aborted) throw cancellationError(controller.signal.reason);
343
- if (actualDigest !== verification.sha256) throw new BackendFederationRemoteEntryError('integrity_mismatch', `[Module Federation] Backend remote ${options.remote.name} SHA-256 mismatch.`, {
344
- details: {
345
- expected: verification.sha256,
346
- received: actualDigest
347
- }
348
- });
349
- return evaluateBackendFederationCommonJsEntry(options.remote, bytes, options.evaluateCommonJs);
350
- } catch (cause) {
351
- if (!controller.signal.aborted) controller.abort(cause);
352
- await reader?.cancel(cause).catch(()=>void 0);
353
- if (cause instanceof BackendFederationRemoteEntryError && !('aborted' === cause.code && timedOut)) throw cause;
354
- if (controller.signal.aborted && (timedOut || callerAborted)) throw cancellationError(cause);
355
- throw cause;
356
- } finally{
357
- if (timeout) clearTimeout(timeout);
358
- options.signal?.removeEventListener('abort', onCallerAbort);
359
- }
276
+ });
277
+ if (options.signal?.aborted) throw new BackendFederationRemoteEntryError('aborted', `[Module Federation] Backend remote ${options.remote.name} loading was aborted.`, {
278
+ cause: options.signal.reason
279
+ });
280
+ return evaluateBackendFederationCommonJsEntry(options.remote, bytes, options.evaluateCommonJs);
360
281
  }
361
282
  export { BackendFederationRemoteEntryError, evaluateBackendFederationCommonJsEntry, loadBoundedBackendFederationResource, loadVerifiedBackendFederationEntry, redactBackendFederationUrl, resolveBackendFederationRemoteEntryVerification };
@@ -1 +1,2 @@
1
1
  export * from "./crossProjectPolicy.mjs";
2
+ export * from "./operationIdentity.mjs";
@@ -0,0 +1,30 @@
1
+ const DEFAULT_OPERATION_VERSION = 1;
2
+ const deriveOperationVersion = (packageVersion)=>{
3
+ if ('string' != typeof packageVersion) return DEFAULT_OPERATION_VERSION;
4
+ const match = packageVersion.trim().match(/^v?(\d+)\./);
5
+ if (!match) return DEFAULT_OPERATION_VERSION;
6
+ const major = Number.parseInt(match[1], 10);
7
+ return Number.isInteger(major) && major >= 0 ? major : DEFAULT_OPERATION_VERSION;
8
+ };
9
+ const stableOperationStringify = (value)=>{
10
+ if (Array.isArray(value)) return `[${value.map((item)=>stableOperationStringify(item)).join(',')}]`;
11
+ if (value && 'object' == typeof value) {
12
+ const entries = Object.entries(value).filter(([, entryValue])=>void 0 !== entryValue).sort(([a], [b])=>a.localeCompare(b)).map(([key, entryValue])=>`${JSON.stringify(key)}:${stableOperationStringify(entryValue)}`);
13
+ return `{${entries.join(',')}}`;
14
+ }
15
+ return JSON.stringify(value) ?? 'null';
16
+ };
17
+ const serializeOperationContract = (operation, requestId)=>stableOperationStringify({
18
+ httpMethod: String(operation.httpMethod || '').toUpperCase(),
19
+ name: operation.name,
20
+ requestId,
21
+ routePath: operation.routePath,
22
+ ...operation.schemas ? {
23
+ schemas: operation.schemas
24
+ } : {}
25
+ });
26
+ async function digestOperationContract(operation, requestId) {
27
+ const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(serializeOperationContract(operation, requestId)));
28
+ return Array.from(new Uint8Array(digest), (value)=>value.toString(16).padStart(2, '0')).join('');
29
+ }
30
+ export { DEFAULT_OPERATION_VERSION, deriveOperationVersion, digestOperationContract, serializeOperationContract, stableOperationStringify };
@@ -0,0 +1,31 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import node_path from "node:path";
3
+ import { deriveOperationVersion } from "./operationIdentity.mjs";
4
+ function resolveOperationProducer(options) {
5
+ for (const directory of options.directories){
6
+ if (!directory) continue;
7
+ let current = node_path.resolve(directory);
8
+ while(true){
9
+ const filename = node_path.join(current, 'package.json');
10
+ if (existsSync(filename)) {
11
+ options.onDependency?.(filename);
12
+ let metadata = {};
13
+ try {
14
+ metadata = JSON.parse(readFileSync(filename, 'utf8')) ?? {};
15
+ } catch {}
16
+ return {
17
+ requestId: options.requestId?.trim() || 'string' == typeof metadata.name && metadata.name.trim() || 'default',
18
+ operationVersion: deriveOperationVersion(metadata.version)
19
+ };
20
+ }
21
+ const parent = node_path.dirname(current);
22
+ if (parent === current) break;
23
+ current = parent;
24
+ }
25
+ }
26
+ return {
27
+ requestId: options.requestId?.trim() || 'default',
28
+ operationVersion: deriveOperationVersion()
29
+ };
30
+ }
31
+ export { resolveOperationProducer };
@@ -0,0 +1,24 @@
1
+ import { resolveLocalisedLoaderRouteId } from "@modern-js/runtime-extensions/localised-loader-identity";
2
+ import { applyLocalisedUrlsToRoutes } from "@modern-js/runtime-extensions/localised-urls";
3
+ function expandLocalisedLoaderRoutes(routes) {
4
+ const languages = new Set();
5
+ const localisedUrls = {};
6
+ let physical = false;
7
+ const visit = (nodes)=>{
8
+ for (const route of nodes){
9
+ physical ||= 'modernCanonicalPath' in route;
10
+ const identity = Reflect.get(route, 'modernLocalisedRoute');
11
+ if (identity?.paths) {
12
+ localisedUrls[identity.canonicalPath] = identity.paths;
13
+ for (const language of Object.keys(identity.paths))languages.add(language);
14
+ }
15
+ if ('children' in route && route.children) visit(route.children);
16
+ }
17
+ };
18
+ visit(routes);
19
+ return physical || 0 === languages.size ? routes : applyLocalisedUrlsToRoutes(routes, [
20
+ ...languages
21
+ ], localisedUrls);
22
+ }
23
+ const resolveLocalisedLoaderRoute = (requestedRouteId, { routes, matchedRouteIds })=>resolveLocalisedLoaderRouteId(routes, requestedRouteId, matchedRouteIds);
24
+ export { expandLocalisedLoaderRoutes, resolveLocalisedLoaderRoute };
@@ -1,12 +1,12 @@
1
1
  import { setLoaderRouteIdResolver } from "@modern-js/plugin-data-loader/runtime";
2
- import { resolveLocalisedLoaderRouteId } from "@modern-js/runtime-extensions/localised-loader-identity";
3
2
  import { getLoaderCtx } from "@modern-js/server-core";
3
+ import { expandLocalisedLoaderRoutes, resolveLocalisedLoaderRoute } from "./localisedLoader.mjs";
4
4
  function injectLocalisedLoaderPlugin() {
5
5
  return {
6
6
  name: '@modern-js/localised-loader',
7
7
  setup (api) {
8
8
  const handler = async (context, next)=>{
9
- setLoaderRouteIdResolver(getLoaderCtx(context), (requestedRouteId, { routes, matchedRouteIds })=>resolveLocalisedLoaderRouteId(routes, requestedRouteId, matchedRouteIds));
9
+ setLoaderRouteIdResolver(getLoaderCtx(context), resolveLocalisedLoaderRoute, expandLocalisedLoaderRoutes);
10
10
  await next();
11
11
  };
12
12
  api.onPrepare(()=>{
@@ -6,7 +6,8 @@ const fetchJsonWithTimeout = async (url, fetcher, timeout)=>{
6
6
  try {
7
7
  const response = await Promise.race([
8
8
  fetcher(url, {
9
- signal: controller.signal
9
+ signal: controller.signal,
10
+ redirect: 'error'
10
11
  }),
11
12
  new Promise((_, reject)=>{
12
13
  timeoutId = setTimeout(()=>{