@bleedingdev/modern-js-server-runtime-extensions 3.5.0-ultramodern.35 → 3.5.0-ultramodern.37

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 (119) hide show
  1. package/dist/cjs/contract-gate-snapshot-normalization.js +122 -0
  2. package/dist/cjs/contract-gate-snapshot-store/file-store.js +13 -13
  3. package/dist/cjs/contract-gate-snapshot-store/http-store.js +2 -11
  4. package/dist/cjs/contract-gate-snapshot-store/resolve.js +8 -6
  5. package/dist/cjs/contractGateAutopilot.js +8 -77
  6. package/dist/cjs/index.js +6 -25
  7. package/dist/cjs/module-federation-css/manifest.js +3 -18
  8. package/dist/cjs/runtime-fallback-signal/index.js +21 -27
  9. package/dist/cjs/runtime-fallback-signal/model.js +157 -0
  10. package/dist/cjs/runtime-fallback-signal/resolver.js +163 -0
  11. package/dist/cjs/runtime-fallback-signal/{contract-gate.js → store.js} +19 -0
  12. package/dist/cjs/telemetry/envelope.js +74 -0
  13. package/dist/cjs/telemetry/registry.js +20 -72
  14. package/dist/esm/contract-gate-snapshot-normalization.mjs +81 -0
  15. package/dist/esm/contract-gate-snapshot-store/file-store.mjs +7 -7
  16. package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -1
  17. package/dist/esm/contract-gate-snapshot-store/resolve.mjs +7 -5
  18. package/dist/esm/contractGateAutopilot.mjs +7 -76
  19. package/dist/esm/index.mjs +0 -1
  20. package/dist/esm/module-federation-css/manifest.mjs +3 -3
  21. package/dist/esm/runtime-fallback-signal/index.mjs +3 -9
  22. package/dist/esm/runtime-fallback-signal/model.mjs +73 -0
  23. package/dist/esm/runtime-fallback-signal/resolver.mjs +107 -0
  24. package/dist/esm/runtime-fallback-signal/{contract-gate.mjs → store.mjs} +14 -1
  25. package/dist/esm/telemetry/envelope.mjs +63 -1
  26. package/dist/esm/telemetry/registry.mjs +21 -73
  27. package/dist/esm-node/contract-gate-snapshot-normalization.mjs +82 -0
  28. package/dist/esm-node/contract-gate-snapshot-store/file-store.mjs +7 -7
  29. package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +1 -1
  30. package/dist/esm-node/contract-gate-snapshot-store/resolve.mjs +8 -7
  31. package/dist/esm-node/contractGateAutopilot.mjs +7 -76
  32. package/dist/esm-node/index.mjs +0 -1
  33. package/dist/esm-node/module-federation-css/manifest.mjs +3 -3
  34. package/dist/esm-node/runtime-fallback-signal/index.mjs +3 -9
  35. package/dist/esm-node/runtime-fallback-signal/model.mjs +74 -0
  36. package/dist/esm-node/runtime-fallback-signal/resolver.mjs +108 -0
  37. package/dist/esm-node/runtime-fallback-signal/{contract-gate.mjs → store.mjs} +14 -1
  38. package/dist/esm-node/telemetry/envelope.mjs +63 -1
  39. package/dist/esm-node/telemetry/registry.mjs +21 -73
  40. package/dist/types/contract-gate-snapshot-normalization.d.ts +15 -0
  41. package/dist/types/contract-gate-snapshot-store/http-store.d.ts +0 -6
  42. package/dist/types/contractGateAutopilot.d.ts +1 -6
  43. package/dist/types/index.d.ts +0 -1
  44. package/dist/types/module-federation-css/manifest.d.ts +0 -5
  45. package/dist/types/runtime-fallback-signal/index.d.ts +4 -10
  46. package/dist/types/runtime-fallback-signal/model.d.ts +70 -0
  47. package/dist/types/runtime-fallback-signal/resolver.d.ts +29 -0
  48. package/dist/types/runtime-fallback-signal/store.d.ts +4 -0
  49. package/dist/types/telemetry/canaryEvaluation.d.ts +3 -2
  50. package/dist/types/telemetry/envelope.d.ts +10 -0
  51. package/dist/types/telemetry/registry.d.ts +1 -4
  52. package/package.json +9 -9
  53. package/src/contract-gate-snapshot-normalization.ts +155 -0
  54. package/src/contract-gate-snapshot-store/file-store.ts +2 -4
  55. package/src/contract-gate-snapshot-store/http-store.ts +3 -3
  56. package/src/contract-gate-snapshot-store/resolve.ts +8 -4
  57. package/src/contractGateAutopilot.ts +13 -141
  58. package/src/index.ts +0 -16
  59. package/src/module-federation-css/manifest.ts +6 -9
  60. package/src/runtime-fallback-signal/index.ts +23 -25
  61. package/src/runtime-fallback-signal/model.ts +230 -0
  62. package/src/runtime-fallback-signal/resolver.ts +304 -0
  63. package/src/runtime-fallback-signal/{contract-gate.ts → store.ts} +38 -3
  64. package/src/telemetry/canaryEvaluation.ts +2 -2
  65. package/src/telemetry/envelope.ts +84 -0
  66. package/src/telemetry/registry.ts +31 -74
  67. package/tests/telemetryAutopilot.test.ts +141 -0
  68. package/tests/telemetryRegistryQueueMatrix.test.ts +227 -0
  69. package/dist/cjs/runtime-fallback-signal/auth.js +0 -87
  70. package/dist/cjs/runtime-fallback-signal/constants.js +0 -72
  71. package/dist/cjs/runtime-fallback-signal/endpoint.js +0 -50
  72. package/dist/cjs/runtime-fallback-signal/errors.js +0 -44
  73. package/dist/cjs/runtime-fallback-signal/payload.js +0 -72
  74. package/dist/cjs/runtime-fallback-signal/source.js +0 -66
  75. package/dist/cjs/runtime-fallback-signal/state.js +0 -57
  76. package/dist/cjs/runtime-fallback-signal/status.js +0 -47
  77. package/dist/cjs/runtime-fallback-signal/trust-policy.js +0 -108
  78. package/dist/cjs/runtime-fallback-signal/types.js +0 -18
  79. package/dist/esm/runtime-fallback-signal/auth.mjs +0 -40
  80. package/dist/esm/runtime-fallback-signal/constants.mjs +0 -10
  81. package/dist/esm/runtime-fallback-signal/endpoint.mjs +0 -12
  82. package/dist/esm/runtime-fallback-signal/errors.mjs +0 -6
  83. package/dist/esm/runtime-fallback-signal/payload.mjs +0 -31
  84. package/dist/esm/runtime-fallback-signal/source.mjs +0 -22
  85. package/dist/esm/runtime-fallback-signal/state.mjs +0 -16
  86. package/dist/esm/runtime-fallback-signal/status.mjs +0 -9
  87. package/dist/esm/runtime-fallback-signal/trust-policy.mjs +0 -67
  88. package/dist/esm/runtime-fallback-signal/types.mjs +0 -0
  89. package/dist/esm-node/runtime-fallback-signal/auth.mjs +0 -41
  90. package/dist/esm-node/runtime-fallback-signal/constants.mjs +0 -11
  91. package/dist/esm-node/runtime-fallback-signal/endpoint.mjs +0 -13
  92. package/dist/esm-node/runtime-fallback-signal/errors.mjs +0 -7
  93. package/dist/esm-node/runtime-fallback-signal/payload.mjs +0 -32
  94. package/dist/esm-node/runtime-fallback-signal/source.mjs +0 -23
  95. package/dist/esm-node/runtime-fallback-signal/state.mjs +0 -17
  96. package/dist/esm-node/runtime-fallback-signal/status.mjs +0 -10
  97. package/dist/esm-node/runtime-fallback-signal/trust-policy.mjs +0 -68
  98. package/dist/esm-node/runtime-fallback-signal/types.mjs +0 -1
  99. package/dist/types/runtime-fallback-signal/auth.d.ts +0 -18
  100. package/dist/types/runtime-fallback-signal/constants.d.ts +0 -9
  101. package/dist/types/runtime-fallback-signal/contract-gate.d.ts +0 -2
  102. package/dist/types/runtime-fallback-signal/endpoint.d.ts +0 -1
  103. package/dist/types/runtime-fallback-signal/errors.d.ts +0 -2
  104. package/dist/types/runtime-fallback-signal/payload.d.ts +0 -6
  105. package/dist/types/runtime-fallback-signal/source.d.ts +0 -3
  106. package/dist/types/runtime-fallback-signal/state.d.ts +0 -3
  107. package/dist/types/runtime-fallback-signal/status.d.ts +0 -2
  108. package/dist/types/runtime-fallback-signal/trust-policy.d.ts +0 -13
  109. package/dist/types/runtime-fallback-signal/types.d.ts +0 -50
  110. package/src/runtime-fallback-signal/auth.ts +0 -117
  111. package/src/runtime-fallback-signal/constants.ts +0 -19
  112. package/src/runtime-fallback-signal/endpoint.ts +0 -22
  113. package/src/runtime-fallback-signal/errors.ts +0 -10
  114. package/src/runtime-fallback-signal/payload.ts +0 -79
  115. package/src/runtime-fallback-signal/source.ts +0 -49
  116. package/src/runtime-fallback-signal/state.ts +0 -34
  117. package/src/runtime-fallback-signal/status.ts +0 -22
  118. package/src/runtime-fallback-signal/trust-policy.ts +0 -179
  119. package/src/runtime-fallback-signal/types.ts +0 -66
@@ -0,0 +1,81 @@
1
+ const getSnapshotGateEntries = (snapshot)=>{
2
+ const gates = snapshot.gates;
3
+ if (!gates || 'object' != typeof gates) return;
4
+ const entries = [];
5
+ for (const [name, value] of Object.entries(gates)){
6
+ const normalizedName = name.trim();
7
+ if (normalizedName) entries.push([
8
+ normalizedName,
9
+ value
10
+ ]);
11
+ }
12
+ return entries;
13
+ };
14
+ const getSnapshotGateNames = (snapshot)=>{
15
+ const entries = getSnapshotGateEntries(snapshot);
16
+ if (!entries) return;
17
+ const names = new Set();
18
+ for (const [name] of entries)names.add(name);
19
+ return names;
20
+ };
21
+ const normalizeSnapshot = (snapshot, { now, gateStaleAfterMs })=>{
22
+ const output = [];
23
+ const entries = getSnapshotGateEntries(snapshot);
24
+ if (!entries) return output;
25
+ for (const [normalizedName, value] of entries){
26
+ const gate = normalizeGateValue(value, snapshot.updatedAt, now);
27
+ if (!gate) continue;
28
+ if ('number' == typeof gate.expiresAt && Number.isFinite(gate.expiresAt) && gate.expiresAt > 0 && now >= gate.expiresAt) {
29
+ output.push({
30
+ name: normalizedName,
31
+ passed: true,
32
+ reason: void 0,
33
+ updatedAt: gate.updatedAt,
34
+ expiresAt: gate.expiresAt
35
+ });
36
+ continue;
37
+ }
38
+ const isStale = gateStaleAfterMs > 0 && now - gate.updatedAt > gateStaleAfterMs;
39
+ if (isStale) {
40
+ output.push({
41
+ name: normalizedName,
42
+ passed: false,
43
+ reason: gate.reason || 'Gate snapshot is stale',
44
+ updatedAt: gate.updatedAt
45
+ });
46
+ continue;
47
+ }
48
+ output.push({
49
+ name: normalizedName,
50
+ passed: gate.passed,
51
+ reason: gate.reason,
52
+ updatedAt: gate.updatedAt
53
+ });
54
+ }
55
+ return output;
56
+ };
57
+ const normalizeGateValue = (value, snapshotUpdatedAt, now)=>{
58
+ if ('boolean' == typeof value) return {
59
+ passed: value,
60
+ updatedAt: normalizeUpdatedAt(snapshotUpdatedAt, now)
61
+ };
62
+ if (!value || 'object' != typeof value) return;
63
+ const hasPassed = 'boolean' == typeof value.passed;
64
+ const passed = true === value.passed;
65
+ let reason = 'string' == typeof value.reason && value.reason.trim().length > 0 ? value.reason : void 0;
66
+ if (!hasPassed) reason = reason || 'Gate snapshot record missing "passed" boolean';
67
+ return {
68
+ passed,
69
+ reason,
70
+ updatedAt: normalizeUpdatedAt(value.updatedAt ?? snapshotUpdatedAt, now),
71
+ expiresAt: normalizeExpiresAt(value.expiresAt)
72
+ };
73
+ };
74
+ const normalizeUpdatedAt = (value, fallback)=>{
75
+ if ('number' == typeof value && Number.isFinite(value) && value > 0) return value;
76
+ return fallback;
77
+ };
78
+ const normalizeExpiresAt = (value)=>{
79
+ if ('number' == typeof value && Number.isFinite(value) && value > 0) return value;
80
+ };
81
+ export { getSnapshotGateNames, normalizeSnapshot };
@@ -1,20 +1,20 @@
1
+ import { promises } from "node:fs";
2
+ import node_path from "node:path";
1
3
  import { fs } from "@modern-js/utils";
2
- import { promises } from "fs";
3
- import path from "path";
4
4
  import { parseServerRuntimeExtensionsEnv } from "../env.mjs";
5
5
  import { normalizeSnapshot } from "./resolve.mjs";
6
6
  import { CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION, DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH } from "./types.mjs";
7
7
  const resolveContractGateSnapshotPath = (appDirectory, configuredPath)=>{
8
8
  const rawPath = configuredPath || parseServerRuntimeExtensionsEnv().contractGatesFile || DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH;
9
- if (path.isAbsolute(rawPath)) return rawPath;
10
- return path.resolve(appDirectory, rawPath);
9
+ if (node_path.isAbsolute(rawPath)) return rawPath;
10
+ return node_path.resolve(appDirectory, rawPath);
11
11
  };
12
12
  const writeSnapshotFileAtomically = async (resolvedPath, contents)=>{
13
- const directory = path.dirname(resolvedPath);
13
+ const directory = node_path.dirname(resolvedPath);
14
14
  await promises.mkdir(directory, {
15
15
  recursive: true
16
16
  });
17
- const temporaryPath = path.join(directory, `.${path.basename(resolvedPath)}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`);
17
+ const temporaryPath = node_path.join(directory, `.${node_path.basename(resolvedPath)}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`);
18
18
  try {
19
19
  await promises.writeFile(temporaryPath, contents);
20
20
  await promises.rename(temporaryPath, resolvedPath);
@@ -26,7 +26,7 @@ const writeSnapshotFileAtomically = async (resolvedPath, contents)=>{
26
26
  }
27
27
  };
28
28
  const createFileContractGateSnapshotStore = (gateSnapshotPath)=>{
29
- const resolvedPath = path.resolve(gateSnapshotPath);
29
+ const resolvedPath = node_path.resolve(gateSnapshotPath);
30
30
  return {
31
31
  name: `file:${resolvedPath}`,
32
32
  async readSnapshot () {
@@ -89,4 +89,4 @@ const tryResolveBuiltinSnapshotStore = (input)=>{
89
89
  if (!BUILTIN_HTTP_STATE_STORE_MODULES.has(moduleName)) return;
90
90
  return createHttpContractGateSnapshotStore(input.stateStore.options || {});
91
91
  };
92
- export { BUILTIN_HTTP_STATE_STORE_MODULES, createHttpContractGateSnapshotStore, normalizeHttpStoreOptions, tryResolveBuiltinSnapshotStore, withTimeoutAbort };
92
+ export { createHttpContractGateSnapshotStore, tryResolveBuiltinSnapshotStore };
@@ -1,5 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
- import path from "path";
2
+ import node_path from "node:path";
3
+ import { pathToFileURL } from "node:url";
3
4
  import { createFileContractGateSnapshotStore } from "./file-store.mjs";
4
5
  import { tryResolveBuiltinSnapshotStore } from "./http-store.mjs";
5
6
  import { CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION } from "./types.mjs";
@@ -27,15 +28,16 @@ const ensureStoreShape = (store, modulePath)=>{
27
28
  const resolveStoreModulePath = (appDirectory, modulePath)=>{
28
29
  const normalized = modulePath.trim();
29
30
  if (!normalized) throw new Error('Contract gate snapshot stateStore.module must be non-empty');
30
- if (path.isAbsolute(normalized)) return normalized;
31
- if (normalized.startsWith('.')) return path.resolve(appDirectory, normalized);
32
- const appRequire = createRequire(path.join(appDirectory, 'package.json'));
31
+ if (node_path.isAbsolute(normalized)) return normalized;
32
+ if (normalized.startsWith('.')) return node_path.resolve(appDirectory, normalized);
33
+ const appRequire = createRequire(node_path.join(appDirectory, 'package.json'));
33
34
  try {
34
35
  return appRequire.resolve(normalized);
35
36
  } catch (_error) {
36
37
  return normalized;
37
38
  }
38
39
  };
40
+ const toStoreModuleImportSpecifier = (modulePath)=>node_path.isAbsolute(modulePath) ? pathToFileURL(modulePath).href : modulePath;
39
41
  const resolveContractGateSnapshotStore = async (input)=>{
40
42
  const { appDirectory, gateSnapshotPath, stateStore, logger } = input;
41
43
  if (!stateStore?.module) return createFileContractGateSnapshotStore(gateSnapshotPath);
@@ -49,7 +51,7 @@ const resolveContractGateSnapshotStore = async (input)=>{
49
51
  const modulePath = resolveStoreModulePath(appDirectory, stateStore.module);
50
52
  let mod;
51
53
  try {
52
- mod = require(modulePath);
54
+ mod = await import(toStoreModuleImportSpecifier(modulePath));
53
55
  } catch (error) {
54
56
  throw new Error(`[telemetry.canary.autopilot] Failed to load stateStore.module "${stateStore.module}" (${modulePath}): ${error instanceof Error ? error.message : String(error)}`);
55
57
  }
@@ -1,4 +1,5 @@
1
- import { createFileContractGateSnapshotStore } from "./contract-gate-snapshot-store/index.mjs";
1
+ import { getSnapshotGateNames, normalizeSnapshot } from "./contract-gate-snapshot-normalization.mjs";
2
+ import { createFileContractGateSnapshotStore } from "./contract-gate-snapshot-store/file-store.mjs";
2
3
  const DEFAULT_POLL_INTERVAL_MS = 15000;
3
4
  const DEFAULT_GATE_STALE_AFTER_MS = 600000;
4
5
  class ContractGateAutopilot {
@@ -21,8 +22,11 @@ class ContractGateAutopilot {
21
22
  const snapshot = await this.loadSnapshot();
22
23
  if (syncGeneration !== this.syncGeneration) return 0;
23
24
  if (!snapshot) return 0;
24
- const snapshotGateNames = this.getSnapshotGateNames(snapshot);
25
- const gates = this.normalizeSnapshot(snapshot);
25
+ const snapshotGateNames = getSnapshotGateNames(snapshot);
26
+ const gates = normalizeSnapshot(snapshot, {
27
+ now: Date.now(),
28
+ gateStaleAfterMs: this.gateStaleAfterMs
29
+ });
26
30
  let updatedCount = snapshotGateNames ? this.clearOmittedGates(snapshotGateNames) : 0;
27
31
  for (const gate of gates){
28
32
  this.orchestrator.addRequiredContractGate(gate.name);
@@ -36,16 +40,6 @@ class ContractGateAutopilot {
36
40
  }
37
41
  return updatedCount;
38
42
  }
39
- getSnapshotGateNames(snapshot) {
40
- const gates = snapshot.gates;
41
- if (!gates || 'object' != typeof gates) return;
42
- const names = new Set();
43
- for (const name of Object.keys(gates)){
44
- const normalizedName = name.trim();
45
- if (normalizedName) names.add(normalizedName);
46
- }
47
- return names;
48
- }
49
43
  clearOmittedGates(snapshotGateNames) {
50
44
  let updatedCount = 0;
51
45
  for (const gateName of Array.from(this.appliedGateFingerprints.keys()))if (!snapshotGateNames.has(gateName)) {
@@ -67,69 +61,6 @@ class ContractGateAutopilot {
67
61
  return;
68
62
  }
69
63
  }
70
- normalizeSnapshot(snapshot) {
71
- const now = Date.now();
72
- const output = [];
73
- const gates = snapshot.gates;
74
- if (!gates || 'object' != typeof gates) return output;
75
- for (const [name, value] of Object.entries(gates)){
76
- const normalizedName = name.trim();
77
- if (!normalizedName) continue;
78
- const gate = this.normalizeGateValue(value, snapshot.updatedAt, now);
79
- if (!gate) continue;
80
- if ('number' == typeof gate.expiresAt && Number.isFinite(gate.expiresAt) && gate.expiresAt > 0 && now >= gate.expiresAt) {
81
- output.push({
82
- name: normalizedName,
83
- passed: true,
84
- reason: void 0,
85
- updatedAt: gate.updatedAt,
86
- expiresAt: gate.expiresAt
87
- });
88
- continue;
89
- }
90
- const isStale = this.gateStaleAfterMs > 0 && now - gate.updatedAt > this.gateStaleAfterMs;
91
- if (isStale) {
92
- output.push({
93
- name: normalizedName,
94
- passed: false,
95
- reason: gate.reason || 'Gate snapshot is stale',
96
- updatedAt: gate.updatedAt
97
- });
98
- continue;
99
- }
100
- output.push({
101
- name: normalizedName,
102
- passed: gate.passed,
103
- reason: gate.reason,
104
- updatedAt: gate.updatedAt
105
- });
106
- }
107
- return output;
108
- }
109
- normalizeGateValue(value, snapshotUpdatedAt, now) {
110
- if ('boolean' == typeof value) return {
111
- passed: value,
112
- updatedAt: this.normalizeUpdatedAt(snapshotUpdatedAt, now)
113
- };
114
- if (!value || 'object' != typeof value) return;
115
- const hasPassed = 'boolean' == typeof value.passed;
116
- const passed = true === value.passed;
117
- let reason = 'string' == typeof value.reason && value.reason.trim().length > 0 ? value.reason : void 0;
118
- if (!hasPassed) reason = reason || 'Gate snapshot record is missing "passed" boolean';
119
- return {
120
- passed,
121
- reason,
122
- updatedAt: this.normalizeUpdatedAt(value.updatedAt ?? snapshotUpdatedAt, now),
123
- expiresAt: this.normalizeExpiresAt(value.expiresAt)
124
- };
125
- }
126
- normalizeUpdatedAt(value, fallback) {
127
- if ('number' == typeof value && Number.isFinite(value) && value > 0) return value;
128
- return fallback;
129
- }
130
- normalizeExpiresAt(value) {
131
- if ('number' == typeof value && Number.isFinite(value) && value > 0) return value;
132
- }
133
64
  constructor(options){
134
65
  this.syncGeneration = 0;
135
66
  this.appliedGateFingerprints = new Map();
@@ -1,4 +1,3 @@
1
- export { CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION, DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH, createFileContractGateSnapshotStore, createHttpContractGateSnapshotStore, resolveContractGateSnapshotPath, resolveContractGateSnapshotStore } from "./contract-gate-snapshot-store/index.mjs";
2
1
  export { ContractGateAutopilot } from "./contractGateAutopilot.mjs";
3
2
  export { DEFAULT_ENVIRONMENT_NAME, parseServerRuntimeExtensionsEnv } from "./env.mjs";
4
3
  export { getRequestPathname, injectMfAssetCacheHeadersPlugin, isMfManifestAsset, isMfRemoteEntryAsset, resolveMfAssetCacheHeaders } from "./mfCache.mjs";
@@ -1,6 +1,6 @@
1
+ import node_path from "node:path";
1
2
  import { fileReader } from "@modern-js/runtime-utils/fileReader";
2
3
  import { fs } from "@modern-js/utils";
3
- import path from "path";
4
4
  const MODULE_FEDERATION_MANIFEST_FILE = 'mf-manifest.json';
5
5
  const warn = (monitors, message, ...args)=>{
6
6
  if (monitors) return void monitors.warn(message, ...args);
@@ -55,7 +55,7 @@ const collectModuleFederationManifestCss = (manifest, manifestUrl)=>{
55
55
  return result;
56
56
  };
57
57
  const getHostManifest = async (pwd, monitors)=>{
58
- const manifestPath = path.join(pwd, MODULE_FEDERATION_MANIFEST_FILE);
58
+ const manifestPath = node_path.join(pwd, MODULE_FEDERATION_MANIFEST_FILE);
59
59
  if (!await fs.pathExists(manifestPath)) return;
60
60
  const manifestBuffer = await fileReader.readFileFromSystem(manifestPath, 'buffer');
61
61
  if (null === manifestBuffer) return;
@@ -66,4 +66,4 @@ const getHostManifest = async (pwd, monitors)=>{
66
66
  return;
67
67
  }
68
68
  };
69
- export { appendResolvedCssAssets, collectModuleFederationManifestCss, ensureTrailingSlash, getCssAssets, getHostManifest, getManifestFallbackBase, getManifestPublicPathBase, normalizeRemoteEntry, tryResolveUrl, warn };
69
+ export { collectModuleFederationManifestCss, ensureTrailingSlash, getHostManifest, normalizeRemoteEntry, warn };
@@ -1,9 +1,3 @@
1
- export { enforceRuntimeFallbackSignalAuth, enforceRuntimeFallbackSignalAuthToken, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig } from "./auth.mjs";
2
- export { DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS, DEFAULT_RUNTIME_FALLBACK_GATE_NAME, DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES, DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, DEFAULT_RUNTIME_STATUS_ENDPOINT } from "./constants.mjs";
3
- export { persistRuntimeFallbackContractGate } from "./contract-gate.mjs";
4
- export { resolveRuntimeFallbackSignalEndpoint } from "./endpoint.mjs";
5
- export { createRuntimeSignalError } from "./errors.mjs";
6
- export { parseRuntimeFallbackSignalPayload, parseRuntimeFallbackSignalPayloadFromRawBody } from "./payload.mjs";
7
- export { createRuntimeFallbackSignalRuntimeState } from "./state.mjs";
8
- export { getRuntimeSignalErrorStatusCode } from "./status.mjs";
9
- export { enforceRuntimeFallbackSignalTrustPolicy, normalizeRuntimeFallbackTrustPolicy } from "./trust-policy.mjs";
1
+ export { DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS, DEFAULT_RUNTIME_FALLBACK_GATE_NAME, DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES, DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, DEFAULT_RUNTIME_STATUS_ENDPOINT, createRuntimeSignalError, getRuntimeSignalErrorStatusCode, parseRuntimeFallbackSignalPayload, parseRuntimeFallbackSignalPayloadFromRawBody } from "./model.mjs";
2
+ export { enforceRuntimeFallbackSignalAuth, enforceRuntimeFallbackSignalAuthToken, enforceRuntimeFallbackSignalTrustPolicy, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, resolveRuntimeFallbackSignalEndpoint } from "./resolver.mjs";
3
+ export { createRuntimeFallbackSignalRuntimeState, persistRuntimeFallbackContractGate } from "./store.mjs";
@@ -0,0 +1,73 @@
1
+ const DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = '/_modern/contract-gates/runtime-fallback';
2
+ const DEFAULT_RUNTIME_STATUS_ENDPOINT = '/_modern/runtime/status';
3
+ const DEFAULT_RUNTIME_FALLBACK_GATE_NAME = 'runtime-mf-fallback-health';
4
+ const DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS = 300000;
5
+ const DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES = 16384;
6
+ const DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER = 'x-modernjs-runtime-signal-token';
7
+ const DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW = 30;
8
+ const DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS = 60000;
9
+ const DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS = 10000;
10
+ function createRuntimeSignalError(message, code) {
11
+ const error = new Error(message);
12
+ error.code = code;
13
+ return error;
14
+ }
15
+ function getRuntimeSignalErrorStatusCode(signalError) {
16
+ if ('PAYLOAD_TOO_LARGE' === signalError.code) return 413;
17
+ if ('INVALID_PAYLOAD' === signalError.code) return 400;
18
+ if ('UNAUTHORIZED' === signalError.code) return 401;
19
+ if ('RATE_LIMITED' === signalError.code) return 429;
20
+ if ('UNTRUSTED_SOURCE' === signalError.code) return 403;
21
+ return 500;
22
+ }
23
+ function normalizeRuntimeSignalOrigin(value) {
24
+ if ('string' != typeof value || 0 === value.trim().length) return;
25
+ try {
26
+ return new URL(value).origin;
27
+ } catch (_error) {
28
+ return;
29
+ }
30
+ }
31
+ function normalizeRuntimeSignalAppName(payload) {
32
+ if ('string' != typeof payload.appName) return 'unknown';
33
+ const normalized = payload.appName.trim();
34
+ return normalized.length > 0 ? normalized : 'unknown';
35
+ }
36
+ function normalizeRuntimeSignalRuntimeDigest(payload) {
37
+ if ('string' == typeof payload.runtimeDigest && payload.runtimeDigest.trim()) return payload.runtimeDigest.trim();
38
+ const metadata = payload.metadata;
39
+ if (metadata && 'object' == typeof metadata && !Array.isArray(metadata) && 'string' == typeof metadata.runtimeDigest) {
40
+ const digest = String(metadata.runtimeDigest).trim();
41
+ if (digest) return digest;
42
+ }
43
+ }
44
+ function getUtf8ByteLength(input) {
45
+ if ("u" > typeof Buffer) return Buffer.byteLength(input);
46
+ return new TextEncoder().encode(input).length;
47
+ }
48
+ async function parseRuntimeFallbackSignalPayload(c, maxBodyBytes) {
49
+ const contentLengthHeader = c.req.header('content-length');
50
+ if (contentLengthHeader) {
51
+ const contentLength = Number.parseInt(contentLengthHeader, 10);
52
+ if (Number.isFinite(contentLength) && contentLength > maxBodyBytes) throw createRuntimeSignalError('runtime fallback signal payload too large', 'PAYLOAD_TOO_LARGE');
53
+ }
54
+ const rawBody = await c.req.raw.text();
55
+ const payload = parseRuntimeFallbackSignalPayloadFromRawBody(rawBody, maxBodyBytes);
56
+ return {
57
+ rawBody,
58
+ payload
59
+ };
60
+ }
61
+ function parseRuntimeFallbackSignalPayloadFromRawBody(rawBody, maxBodyBytes) {
62
+ if (!rawBody || 0 === rawBody.trim().length) throw createRuntimeSignalError('runtime fallback signal body empty', 'INVALID_PAYLOAD');
63
+ if (getUtf8ByteLength(rawBody) > maxBodyBytes) throw createRuntimeSignalError('runtime fallback signal payload too large', 'PAYLOAD_TOO_LARGE');
64
+ let payload;
65
+ try {
66
+ payload = JSON.parse(rawBody);
67
+ } catch (_error) {
68
+ throw createRuntimeSignalError('runtime fallback signal body must be valid JSON', 'INVALID_PAYLOAD');
69
+ }
70
+ if (!payload || 'object' != typeof payload || Array.isArray(payload)) throw createRuntimeSignalError('runtime fallback signal body must be a JSON object', 'INVALID_PAYLOAD');
71
+ return payload;
72
+ }
73
+ export { DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER, DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS, DEFAULT_RUNTIME_FALLBACK_GATE_NAME, DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES, DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS, DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW, DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS, DEFAULT_RUNTIME_STATUS_ENDPOINT, createRuntimeSignalError, getRuntimeSignalErrorStatusCode, normalizeRuntimeSignalAppName, normalizeRuntimeSignalOrigin, normalizeRuntimeSignalRuntimeDigest, parseRuntimeFallbackSignalPayload, parseRuntimeFallbackSignalPayloadFromRawBody };
@@ -0,0 +1,107 @@
1
+ import { createHash, timingSafeEqual } from "node:crypto";
2
+ import { DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER, DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS, DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW, DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS, createRuntimeSignalError, normalizeRuntimeSignalAppName, normalizeRuntimeSignalOrigin, normalizeRuntimeSignalRuntimeDigest } from "./model.mjs";
3
+ import { cleanupRuntimeFallbackSignalRuntimeState } from "./store.mjs";
4
+ function resolveRuntimeFallbackSignalEndpoint(configuredEndpoint) {
5
+ if ('string' == typeof configuredEndpoint && configuredEndpoint.trim()) return configuredEndpoint.trim();
6
+ return DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT;
7
+ }
8
+ function normalizeRuntimeFallbackSignalAuthConfig(configured) {
9
+ const headerName = 'string' == typeof configured?.headerName && configured.headerName.trim() ? configured.headerName.trim().toLowerCase() : DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER;
10
+ const expectedFromEnv = 'string' == typeof configured?.expectedValueEnv && configured.expectedValueEnv.trim().length > 0 ? process.env[configured.expectedValueEnv.trim()] : void 0;
11
+ const expectedFromConfig = 'string' == typeof configured?.expectedValue && configured.expectedValue.trim().length > 0 ? configured.expectedValue.trim() : void 0;
12
+ const expectedValue = expectedFromConfig || expectedFromEnv;
13
+ const enabled = configured?.enabled === true;
14
+ if (enabled && !expectedValue) throw new Error('[telemetry.canary.autopilot.runtimeFallbackSignal] auth.enabled true but no expected token configured');
15
+ return {
16
+ enabled,
17
+ headerName,
18
+ expectedValue
19
+ };
20
+ }
21
+ function normalizeRequiredRuntimeFallbackSignalAuthConfig(configured) {
22
+ if (configured?.enabled === false) throw new Error('[telemetry.canary.autopilot.runtimeFallbackSignal] auth.enabled cannot be false when runtimeFallbackSignal.enabled is true');
23
+ const authConfig = normalizeRuntimeFallbackSignalAuthConfig(configured);
24
+ if (!authConfig.expectedValue) throw new Error('[telemetry.canary.autopilot.runtimeFallbackSignal] auth.expectedValue or auth.expectedValueEnv is required when runtimeFallbackSignal.enabled is true');
25
+ return {
26
+ ...authConfig,
27
+ enabled: true
28
+ };
29
+ }
30
+ function safeTokenEquals(candidate, expected) {
31
+ const candidateDigest = createHash('sha256').update(candidate).digest();
32
+ const expectedDigest = createHash('sha256').update(expected).digest();
33
+ return timingSafeEqual(candidateDigest, expectedDigest);
34
+ }
35
+ function enforceRuntimeFallbackSignalAuthToken(token, authConfig) {
36
+ if (!authConfig.enabled) return;
37
+ if (!token || !authConfig.expectedValue || !safeTokenEquals(token, authConfig.expectedValue)) throw createRuntimeSignalError('runtime fallback signal auth failed', 'UNAUTHORIZED');
38
+ }
39
+ function enforceRuntimeFallbackSignalAuth(c, runtimeSignalConfig) {
40
+ enforceRuntimeFallbackSignalAuthToken(c.req.header(runtimeSignalConfig.auth.headerName), runtimeSignalConfig.auth);
41
+ }
42
+ const normalizeInteger = (value, fallback, minimum)=>{
43
+ const candidate = 'number' == typeof value && Number.isFinite(value) ? value : fallback;
44
+ return Math.max(minimum, Math.floor(candidate));
45
+ };
46
+ function normalizeRuntimeFallbackTrustPolicy(configured) {
47
+ const allowedApps = Array.isArray(configured?.allowedApps) ? configured.allowedApps.map((item)=>'string' == typeof item ? item.trim() : '').filter(Boolean) : [];
48
+ const allowedEntryOrigins = Array.isArray(configured?.allowedEntryOrigins) ? configured.allowedEntryOrigins.map((item)=>normalizeRuntimeSignalOrigin(item)).filter((item)=>Boolean(item)) : [];
49
+ const expectedRuntimeDigests = {};
50
+ Object.entries(configured?.expectedRuntimeDigests || {}).forEach(([appName, digest])=>{
51
+ if ('string' == typeof appName && appName.trim().length > 0 && 'string' == typeof digest && digest.trim().length > 0) expectedRuntimeDigests[appName.trim()] = digest.trim();
52
+ });
53
+ return {
54
+ allowedApps,
55
+ allowedEntryOrigins,
56
+ expectedRuntimeDigests,
57
+ enforceRuntimeDigest: configured?.enforceRuntimeDigest === true,
58
+ maxSignalsPerWindow: normalizeInteger(configured?.maxSignalsPerWindow, DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW, 1),
59
+ windowMs: normalizeInteger(configured?.windowMs, DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS, 1),
60
+ dedupeWindowMs: normalizeInteger(configured?.dedupeWindowMs, DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS, 0)
61
+ };
62
+ }
63
+ function enforceRuntimeFallbackSignalTrustPolicy(payload, runtimeSignalContext, source = {}) {
64
+ const { trustPolicy, runtimeState } = runtimeSignalContext;
65
+ const now = Date.now();
66
+ cleanupRuntimeFallbackSignalRuntimeState(now, runtimeState, trustPolicy);
67
+ const appName = normalizeRuntimeSignalAppName(payload);
68
+ const entryOrigin = normalizeRuntimeSignalOrigin(payload.entry);
69
+ const runtimeDigest = normalizeRuntimeSignalRuntimeDigest(payload);
70
+ if (trustPolicy.allowedApps.length > 0 && !trustPolicy.allowedApps.includes(appName)) throw createRuntimeSignalError(`runtime fallback signal app "${appName}" is not trusted`, 'UNTRUSTED_SOURCE');
71
+ if (trustPolicy.allowedEntryOrigins.length > 0) {
72
+ if (!entryOrigin || !trustPolicy.allowedEntryOrigins.includes(entryOrigin)) throw createRuntimeSignalError(`runtime fallback signal entry origin "${entryOrigin || 'unknown'}" is not trusted`, 'UNTRUSTED_SOURCE');
73
+ }
74
+ const expectedDigest = trustPolicy.expectedRuntimeDigests[appName];
75
+ if (expectedDigest && runtimeDigest !== expectedDigest) throw createRuntimeSignalError(`runtime fallback runtimeDigest mismatch for app "${appName}"`, 'UNTRUSTED_SOURCE');
76
+ if (trustPolicy.enforceRuntimeDigest && !runtimeDigest) throw createRuntimeSignalError(`runtime fallback signal app "${appName}" missing runtimeDigest`, 'UNTRUSTED_SOURCE');
77
+ const dedupeFingerprint = JSON.stringify({
78
+ appName,
79
+ entryOrigin: entryOrigin || 'unknown',
80
+ reason: payload.reason || 'runtime_fallback',
81
+ phase: payload.phase || 'unknown',
82
+ runtimeDigest: runtimeDigest || 'unknown'
83
+ });
84
+ const dedupeWindowMs = trustPolicy.dedupeWindowMs;
85
+ if (dedupeWindowMs > 0) {
86
+ const lastSeenAt = runtimeState.dedupeByFingerprint.get(dedupeFingerprint);
87
+ runtimeState.dedupeByFingerprint.set(dedupeFingerprint, now);
88
+ if ('number' == typeof lastSeenAt && now - lastSeenAt <= dedupeWindowMs) return {
89
+ deduped: true
90
+ };
91
+ } else runtimeState.dedupeByFingerprint.set(dedupeFingerprint, now);
92
+ const remoteAddress = source.remoteAddress?.trim();
93
+ const sourceKey = remoteAddress || 'unknown-remote';
94
+ const rateState = runtimeState.rateLimitBySource.get(sourceKey);
95
+ if (!rateState || now - rateState.windowStartedAt > trustPolicy.windowMs) runtimeState.rateLimitBySource.set(sourceKey, {
96
+ count: 1,
97
+ windowStartedAt: now
98
+ });
99
+ else {
100
+ if (rateState.count >= trustPolicy.maxSignalsPerWindow) throw createRuntimeSignalError(`runtime fallback signal rate-limited source "${sourceKey}"`, 'RATE_LIMITED');
101
+ rateState.count += 1;
102
+ }
103
+ return {
104
+ deduped: false
105
+ };
106
+ }
107
+ export { enforceRuntimeFallbackSignalAuth, enforceRuntimeFallbackSignalAuthToken, enforceRuntimeFallbackSignalTrustPolicy, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, resolveRuntimeFallbackSignalEndpoint };
@@ -1,4 +1,17 @@
1
1
  import { CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION } from "../contract-gate-snapshot-store/index.mjs";
2
+ function createRuntimeFallbackSignalRuntimeState() {
3
+ return {
4
+ rateLimitBySource: new Map(),
5
+ dedupeByFingerprint: new Map()
6
+ };
7
+ }
8
+ function cleanupRuntimeFallbackSignalRuntimeState(now, runtimeState, trustPolicy) {
9
+ const rateLimitWindowMs = Math.max(1, trustPolicy.windowMs);
10
+ for (const [sourceKey, rateState] of runtimeState.rateLimitBySource)if (now - rateState.windowStartedAt > rateLimitWindowMs) runtimeState.rateLimitBySource.delete(sourceKey);
11
+ const dedupeWindowMs = Math.max(0, trustPolicy.dedupeWindowMs);
12
+ if (0 === dedupeWindowMs) return void runtimeState.dedupeByFingerprint.clear();
13
+ for (const [fingerprint, lastSeenAt] of runtimeState.dedupeByFingerprint)if (now - lastSeenAt > dedupeWindowMs) runtimeState.dedupeByFingerprint.delete(fingerprint);
14
+ }
2
15
  async function persistRuntimeFallbackContractGate(payload, runtimeSignalConfig) {
3
16
  const now = Date.now();
4
17
  const gateSnapshotStore = await runtimeSignalConfig.gateSnapshotStore;
@@ -23,4 +36,4 @@ async function persistRuntimeFallbackContractGate(payload, runtimeSignalConfig)
23
36
  };
24
37
  await gateSnapshotStore.writeSnapshot(snapshot);
25
38
  }
26
- export { persistRuntimeFallbackContractGate };
39
+ export { cleanupRuntimeFallbackSignalRuntimeState, createRuntimeFallbackSignalRuntimeState, persistRuntimeFallbackContractGate };
@@ -1,3 +1,65 @@
1
+ function buildDroppedEnvelope(context, droppedCount) {
2
+ return {
3
+ timestamp: Date.now(),
4
+ service: context.service,
5
+ module: context.module,
6
+ environment: context.environment,
7
+ signalType: 'metric',
8
+ name: 'telemetry.queue.dropped',
9
+ value: droppedCount,
10
+ unit: 'count',
11
+ tags: {
12
+ reason: 'queue_backpressure'
13
+ }
14
+ };
15
+ }
16
+ function buildQueueDepthEnvelope(context, queueDepth) {
17
+ return {
18
+ timestamp: Date.now(),
19
+ service: context.service,
20
+ module: context.module,
21
+ environment: context.environment,
22
+ signalType: 'metric',
23
+ name: 'telemetry.queue.depth',
24
+ value: queueDepth,
25
+ unit: 'count',
26
+ tags: {
27
+ capacity: String(context.maxQueueSize)
28
+ }
29
+ };
30
+ }
31
+ function buildQueueUtilizationEnvelope(context, queueDepth) {
32
+ return {
33
+ timestamp: Date.now(),
34
+ service: context.service,
35
+ module: context.module,
36
+ environment: context.environment,
37
+ signalType: 'metric',
38
+ name: 'telemetry.queue.utilization',
39
+ value: queueDepth / context.maxQueueSize,
40
+ unit: 'ratio',
41
+ tags: {
42
+ capacity: String(context.maxQueueSize)
43
+ }
44
+ };
45
+ }
46
+ function buildStartupProbeEnvelope(context) {
47
+ return {
48
+ timestamp: Date.now(),
49
+ service: context.service,
50
+ module: context.module,
51
+ environment: context.environment,
52
+ signalType: 'log',
53
+ name: 'telemetry.exporter.startup_probe',
54
+ level: 'info',
55
+ tags: {
56
+ phase: 'startup'
57
+ },
58
+ attributes: {
59
+ source: 'TelemetryRegistry'
60
+ }
61
+ };
62
+ }
1
63
  function clamp(value, min, max) {
2
64
  if (Number.isNaN(value)) return max;
3
65
  return Math.max(min, Math.min(max, value));
@@ -99,4 +161,4 @@ function toTelemetryEnvelope(event, input) {
99
161
  }
100
162
  };
101
163
  }
102
- export { clamp, isRecord, redactObject, toTelemetryEnvelope };
164
+ export { buildDroppedEnvelope, buildQueueDepthEnvelope, buildQueueUtilizationEnvelope, buildStartupProbeEnvelope, clamp, isRecord, redactObject, toTelemetryEnvelope };