@bleedingdev/modern-js-server-runtime-extensions 3.5.0-ultramodern.36 → 3.5.0-ultramodern.38

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 +10 -10
  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
@@ -1,5 +1,18 @@
1
1
  import "node:module";
2
2
  import { CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION } from "../contract-gate-snapshot-store/index.mjs";
3
+ function createRuntimeFallbackSignalRuntimeState() {
4
+ return {
5
+ rateLimitBySource: new Map(),
6
+ dedupeByFingerprint: new Map()
7
+ };
8
+ }
9
+ function cleanupRuntimeFallbackSignalRuntimeState(now, runtimeState, trustPolicy) {
10
+ const rateLimitWindowMs = Math.max(1, trustPolicy.windowMs);
11
+ for (const [sourceKey, rateState] of runtimeState.rateLimitBySource)if (now - rateState.windowStartedAt > rateLimitWindowMs) runtimeState.rateLimitBySource.delete(sourceKey);
12
+ const dedupeWindowMs = Math.max(0, trustPolicy.dedupeWindowMs);
13
+ if (0 === dedupeWindowMs) return void runtimeState.dedupeByFingerprint.clear();
14
+ for (const [fingerprint, lastSeenAt] of runtimeState.dedupeByFingerprint)if (now - lastSeenAt > dedupeWindowMs) runtimeState.dedupeByFingerprint.delete(fingerprint);
15
+ }
3
16
  async function persistRuntimeFallbackContractGate(payload, runtimeSignalConfig) {
4
17
  const now = Date.now();
5
18
  const gateSnapshotStore = await runtimeSignalConfig.gateSnapshotStore;
@@ -24,4 +37,4 @@ async function persistRuntimeFallbackContractGate(payload, runtimeSignalConfig)
24
37
  };
25
38
  await gateSnapshotStore.writeSnapshot(snapshot);
26
39
  }
27
- export { persistRuntimeFallbackContractGate };
40
+ export { cleanupRuntimeFallbackSignalRuntimeState, createRuntimeFallbackSignalRuntimeState, persistRuntimeFallbackContractGate };
@@ -1,4 +1,66 @@
1
1
  import "node:module";
2
+ function buildDroppedEnvelope(context, droppedCount) {
3
+ return {
4
+ timestamp: Date.now(),
5
+ service: context.service,
6
+ module: context.module,
7
+ environment: context.environment,
8
+ signalType: 'metric',
9
+ name: 'telemetry.queue.dropped',
10
+ value: droppedCount,
11
+ unit: 'count',
12
+ tags: {
13
+ reason: 'queue_backpressure'
14
+ }
15
+ };
16
+ }
17
+ function buildQueueDepthEnvelope(context, queueDepth) {
18
+ return {
19
+ timestamp: Date.now(),
20
+ service: context.service,
21
+ module: context.module,
22
+ environment: context.environment,
23
+ signalType: 'metric',
24
+ name: 'telemetry.queue.depth',
25
+ value: queueDepth,
26
+ unit: 'count',
27
+ tags: {
28
+ capacity: String(context.maxQueueSize)
29
+ }
30
+ };
31
+ }
32
+ function buildQueueUtilizationEnvelope(context, queueDepth) {
33
+ return {
34
+ timestamp: Date.now(),
35
+ service: context.service,
36
+ module: context.module,
37
+ environment: context.environment,
38
+ signalType: 'metric',
39
+ name: 'telemetry.queue.utilization',
40
+ value: queueDepth / context.maxQueueSize,
41
+ unit: 'ratio',
42
+ tags: {
43
+ capacity: String(context.maxQueueSize)
44
+ }
45
+ };
46
+ }
47
+ function buildStartupProbeEnvelope(context) {
48
+ return {
49
+ timestamp: Date.now(),
50
+ service: context.service,
51
+ module: context.module,
52
+ environment: context.environment,
53
+ signalType: 'log',
54
+ name: 'telemetry.exporter.startup_probe',
55
+ level: 'info',
56
+ tags: {
57
+ phase: 'startup'
58
+ },
59
+ attributes: {
60
+ source: 'TelemetryRegistry'
61
+ }
62
+ };
63
+ }
2
64
  function clamp(value, min, max) {
3
65
  if (Number.isNaN(value)) return max;
4
66
  return Math.max(min, Math.min(max, value));
@@ -100,4 +162,4 @@ function toTelemetryEnvelope(event, input) {
100
162
  }
101
163
  };
102
164
  }
103
- export { clamp, isRecord, redactObject, toTelemetryEnvelope };
165
+ export { buildDroppedEnvelope, buildQueueDepthEnvelope, buildQueueUtilizationEnvelope, buildStartupProbeEnvelope, clamp, isRecord, redactObject, toTelemetryEnvelope };
@@ -1,5 +1,5 @@
1
1
  import "node:module";
2
- import { clamp, redactObject } from "./envelope.mjs";
2
+ import { buildDroppedEnvelope, buildQueueDepthEnvelope, buildQueueUtilizationEnvelope, buildStartupProbeEnvelope, clamp, redactObject } from "./envelope.mjs";
3
3
  import { TelemetryStartupHealthError } from "./registryTypes.mjs";
4
4
  class TelemetryRegistry {
5
5
  async register(exporter) {
@@ -87,10 +87,7 @@ class TelemetryRegistry {
87
87
  }
88
88
  enqueueMetric(input) {
89
89
  this.enqueue({
90
- timestamp: Date.now(),
91
- service: this.service,
92
- module: this.module,
93
- environment: this.environment,
90
+ ...this.baseEnvelope(),
94
91
  signalType: 'metric',
95
92
  name: input.name,
96
93
  value: input.value,
@@ -104,10 +101,7 @@ class TelemetryRegistry {
104
101
  }
105
102
  enqueueLog(input) {
106
103
  this.enqueue({
107
- timestamp: Date.now(),
108
- service: this.service,
109
- module: this.module,
110
- environment: this.environment,
104
+ ...this.baseEnvelope(),
111
105
  signalType: 'log',
112
106
  name: input.name,
113
107
  level: input.level,
@@ -121,10 +115,7 @@ class TelemetryRegistry {
121
115
  }
122
116
  enqueueTrace(input) {
123
117
  this.enqueue({
124
- timestamp: Date.now(),
125
- service: this.service,
126
- module: this.module,
127
- environment: this.environment,
118
+ ...this.baseEnvelope(),
128
119
  signalType: 'trace',
129
120
  name: input.name,
130
121
  traceId: input.traceId,
@@ -134,49 +125,12 @@ class TelemetryRegistry {
134
125
  attributes: input.attributes
135
126
  });
136
127
  }
137
- buildDroppedEnvelope(droppedCount) {
128
+ baseEnvelope() {
138
129
  return {
139
130
  timestamp: Date.now(),
140
131
  service: this.service,
141
132
  module: this.module,
142
- environment: this.environment,
143
- signalType: 'metric',
144
- name: 'telemetry.queue.dropped',
145
- value: droppedCount,
146
- unit: 'count',
147
- tags: {
148
- reason: 'queue_backpressure'
149
- }
150
- };
151
- }
152
- buildQueueDepthEnvelope(queueDepth) {
153
- return {
154
- timestamp: Date.now(),
155
- service: this.service,
156
- module: this.module,
157
- environment: this.environment,
158
- signalType: 'metric',
159
- name: 'telemetry.queue.depth',
160
- value: queueDepth,
161
- unit: 'count',
162
- tags: {
163
- capacity: String(this.maxQueueSize)
164
- }
165
- };
166
- }
167
- buildQueueUtilizationEnvelope(queueDepth) {
168
- return {
169
- timestamp: Date.now(),
170
- service: this.service,
171
- module: this.module,
172
- environment: this.environment,
173
- signalType: 'metric',
174
- name: 'telemetry.queue.utilization',
175
- value: queueDepth / this.maxQueueSize,
176
- unit: 'ratio',
177
- tags: {
178
- capacity: String(this.maxQueueSize)
179
- }
133
+ environment: this.environment
180
134
  };
181
135
  }
182
136
  async emitBatch(batch) {
@@ -193,27 +147,15 @@ class TelemetryRegistry {
193
147
  this.markExporterHealthy(exporterName);
194
148
  }
195
149
  }
196
- buildStartupProbeEnvelope() {
197
- return {
198
- timestamp: Date.now(),
199
- service: this.service,
200
- module: this.module,
201
- environment: this.environment,
202
- signalType: 'log',
203
- name: 'telemetry.exporter.startup_probe',
204
- level: 'info',
205
- tags: {
206
- phase: 'startup'
207
- },
208
- attributes: {
209
- source: 'TelemetryRegistry'
210
- }
211
- };
212
- }
213
150
  async startupHealthCheck(options) {
214
151
  if (0 === this.exporters.length) return;
215
152
  const probeBatch = [
216
- this.buildStartupProbeEnvelope()
153
+ buildStartupProbeEnvelope({
154
+ service: this.service,
155
+ module: this.module,
156
+ environment: this.environment,
157
+ maxQueueSize: this.maxQueueSize
158
+ })
217
159
  ];
218
160
  const failedExporters = [];
219
161
  await Promise.all(this.exporters.map(async (exporter)=>{
@@ -246,14 +188,20 @@ class TelemetryRegistry {
246
188
  }
247
189
  async flushInternal() {
248
190
  const queueDepthBeforeFlush = this.queue.length;
191
+ const envelopeContext = {
192
+ service: this.service,
193
+ module: this.module,
194
+ environment: this.environment,
195
+ maxQueueSize: this.maxQueueSize
196
+ };
249
197
  if (queueDepthBeforeFlush > 0) {
250
- this.queue.unshift(this.buildQueueUtilizationEnvelope(queueDepthBeforeFlush));
251
- this.queue.unshift(this.buildQueueDepthEnvelope(queueDepthBeforeFlush));
198
+ this.queue.unshift(buildQueueUtilizationEnvelope(envelopeContext, queueDepthBeforeFlush));
199
+ this.queue.unshift(buildQueueDepthEnvelope(envelopeContext, queueDepthBeforeFlush));
252
200
  }
253
201
  if (this.droppedCount > 0) {
254
202
  const droppedCount = this.droppedCount;
255
203
  this.droppedCount = 0;
256
- this.queue.unshift(this.buildDroppedEnvelope(droppedCount));
204
+ this.queue.unshift(buildDroppedEnvelope(envelopeContext, droppedCount));
257
205
  }
258
206
  if (0 === this.queue.length) return;
259
207
  if (0 === this.exporters.length) {
@@ -0,0 +1,15 @@
1
+ import type { GateSnapshot } from './contract-gate-snapshot-store/types';
2
+ type NormalizedGate = {
3
+ name: string;
4
+ passed: boolean;
5
+ reason?: string;
6
+ updatedAt: number;
7
+ expiresAt?: number;
8
+ };
9
+ type NormalizeSnapshotOptions = {
10
+ now: number;
11
+ gateStaleAfterMs: number;
12
+ };
13
+ export declare const getSnapshotGateNames: (snapshot: GateSnapshot) => Set<string> | undefined;
14
+ export declare const normalizeSnapshot: (snapshot: GateSnapshot, { now, gateStaleAfterMs }: NormalizeSnapshotOptions) => NormalizedGate[];
15
+ export {};
@@ -1,10 +1,4 @@
1
1
  import type { ContractGateSnapshotHttpStoreOptions, ContractGateSnapshotStore, ContractGateSnapshotStoreUserConfig } from './types';
2
- export declare const BUILTIN_HTTP_STATE_STORE_MODULES: Set<string>;
3
- export declare const normalizeHttpStoreOptions: (options: Record<string, unknown> | undefined) => ContractGateSnapshotHttpStoreOptions;
4
- export declare const withTimeoutAbort: (timeoutMs: number) => {
5
- signal: AbortSignal;
6
- clear: () => void;
7
- };
8
2
  export declare const createHttpContractGateSnapshotStore: (options: ContractGateSnapshotHttpStoreOptions) => ContractGateSnapshotStore;
9
3
  export declare const tryResolveBuiltinSnapshotStore: (input: {
10
4
  stateStore: ContractGateSnapshotStoreUserConfig;
@@ -1,4 +1,4 @@
1
- import { type ContractGateSnapshotStore } from './contract-gate-snapshot-store';
1
+ import type { ContractGateSnapshotStore } from './contract-gate-snapshot-store/types';
2
2
  import type { TelemetryCanaryOrchestrator } from './telemetryCore';
3
3
  type LoggerLike = {
4
4
  info?: (message: string) => void;
@@ -26,12 +26,7 @@ export declare class ContractGateAutopilot {
26
26
  start(): Promise<void>;
27
27
  stop(): void;
28
28
  syncOnce(): Promise<number>;
29
- private getSnapshotGateNames;
30
29
  private clearOmittedGates;
31
30
  private loadSnapshot;
32
- private normalizeSnapshot;
33
- private normalizeGateValue;
34
- private normalizeUpdatedAt;
35
- private normalizeExpiresAt;
36
31
  }
37
32
  export {};
@@ -1,4 +1,3 @@
1
- export { CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION, type ContractGateSnapshotHttpStoreOptions, type ContractGateSnapshotStore, type ContractGateSnapshotStoreFactory, type ContractGateSnapshotStoreFactoryContext, type ContractGateSnapshotStoreModule, type ContractGateSnapshotStoreUserConfig, createFileContractGateSnapshotStore, createHttpContractGateSnapshotStore, DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH, type GateSnapshot, type GateSnapshotGateValue, resolveContractGateSnapshotPath, resolveContractGateSnapshotStore, } from './contract-gate-snapshot-store';
2
1
  export { ContractGateAutopilot, type ContractGateAutopilotOptions, } from './contractGateAutopilot';
3
2
  export { DEFAULT_ENVIRONMENT_NAME, parseServerRuntimeExtensionsEnv, type ServerRuntimeExtensionsEnv, } from './env';
4
3
  export { getRequestPathname, injectMfAssetCacheHeadersPlugin, isMfManifestAsset, isMfRemoteEntryAsset, resolveMfAssetCacheHeaders, } from './mfCache';
@@ -22,12 +22,7 @@ export type ModuleFederationManifest = {
22
22
  };
23
23
  export declare const warn: (monitors: Monitors | undefined, message: string, ...args: unknown[]) => void;
24
24
  export declare const ensureTrailingSlash: (value: string) => string;
25
- export declare const tryResolveUrl: (value: string, base: string) => string | undefined;
26
25
  export declare const normalizeRemoteEntry: (entry: string) => string | undefined;
27
- export declare const getCssAssets: (assets?: ModuleFederationAssets) => string[];
28
- export declare const getManifestFallbackBase: (manifestUrl: string) => string;
29
- export declare const getManifestPublicPathBase: (publicPath: string | undefined, manifestUrl: string) => string;
30
- export declare const appendResolvedCssAssets: (result: string[], seen: Set<string>, assets: string[], base: string) => void;
31
26
  export declare const collectModuleFederationManifestCss: (manifest: ModuleFederationManifest, manifestUrl: string) => string[];
32
27
  export declare const getHostManifest: (pwd: string, monitors?: Monitors) => Promise<ModuleFederationManifest | undefined>;
33
28
  export {};
@@ -1,10 +1,4 @@
1
- export { enforceRuntimeFallbackSignalAuth, enforceRuntimeFallbackSignalAuthToken, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, } from './auth';
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';
3
- export { persistRuntimeFallbackContractGate } from './contract-gate';
4
- export { resolveRuntimeFallbackSignalEndpoint } from './endpoint';
5
- export { createRuntimeSignalError } from './errors';
6
- export { parseRuntimeFallbackSignalPayload, parseRuntimeFallbackSignalPayloadFromRawBody, } from './payload';
7
- export { createRuntimeFallbackSignalRuntimeState } from './state';
8
- export { getRuntimeSignalErrorStatusCode } from './status';
9
- export { enforceRuntimeFallbackSignalTrustPolicy, normalizeRuntimeFallbackTrustPolicy, } from './trust-policy';
10
- export type { RuntimeFallbackSignalAuthConfig, RuntimeFallbackSignalConfig, RuntimeFallbackSignalRuntimeState, RuntimeFallbackSignalSource, RuntimeFallbackSignalTrustContext, RuntimeFallbackSignalTrustPolicy, RuntimeSignalError, RuntimeSignalErrorCode, } from './types';
1
+ export type { RuntimeFallbackSignalAuthConfig, RuntimeFallbackSignalConfig, RuntimeFallbackSignalRuntimeState, RuntimeFallbackSignalSource, RuntimeFallbackSignalTrustContext, RuntimeFallbackSignalTrustPolicy, RuntimeSignalError, RuntimeSignalErrorCode, } from './model';
2
+ export { createRuntimeSignalError, 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, getRuntimeSignalErrorStatusCode, parseRuntimeFallbackSignalPayload, parseRuntimeFallbackSignalPayloadFromRawBody, } from './model';
3
+ export { enforceRuntimeFallbackSignalAuth, enforceRuntimeFallbackSignalAuthToken, enforceRuntimeFallbackSignalTrustPolicy, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, resolveRuntimeFallbackSignalEndpoint, } from './resolver';
4
+ export { createRuntimeFallbackSignalRuntimeState, persistRuntimeFallbackContractGate, } from './store';
@@ -0,0 +1,70 @@
1
+ import type { Context, ServerEnv } from '@modern-js/server-core';
2
+ import type { ContractGateSnapshotStore } from '../contract-gate-snapshot-store';
3
+ export declare const DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = "/_modern/contract-gates/runtime-fallback";
4
+ export declare const DEFAULT_RUNTIME_STATUS_ENDPOINT = "/_modern/runtime/status";
5
+ export declare const DEFAULT_RUNTIME_FALLBACK_GATE_NAME = "runtime-mf-fallback-health";
6
+ export declare const DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS: number;
7
+ export declare const DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES: number;
8
+ export declare const DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER = "x-modernjs-runtime-signal-token";
9
+ export declare const DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW = 30;
10
+ export declare const DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS = 60000;
11
+ export declare const DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS = 10000;
12
+ export type RuntimeSignalErrorCode = 'PAYLOAD_TOO_LARGE' | 'INVALID_PAYLOAD' | 'RATE_LIMITED' | 'UNAUTHORIZED' | 'UNTRUSTED_SOURCE';
13
+ export type RuntimeSignalError = Error & {
14
+ code?: RuntimeSignalErrorCode;
15
+ };
16
+ export type RuntimeFallbackSignalTrustPolicy = {
17
+ allowedApps: string[];
18
+ allowedEntryOrigins: string[];
19
+ expectedRuntimeDigests: Record<string, string>;
20
+ enforceRuntimeDigest: boolean;
21
+ maxSignalsPerWindow: number;
22
+ windowMs: number;
23
+ dedupeWindowMs: number;
24
+ };
25
+ type RuntimeFallbackSignalRateLimitState = {
26
+ count: number;
27
+ windowStartedAt: number;
28
+ };
29
+ export type RuntimeFallbackSignalAuthConfig = {
30
+ enabled: boolean;
31
+ headerName: string;
32
+ expectedValue?: string;
33
+ };
34
+ export type RuntimeFallbackSignalRuntimeState = {
35
+ rateLimitBySource: Map<string, RuntimeFallbackSignalRateLimitState>;
36
+ dedupeByFingerprint: Map<string, number>;
37
+ };
38
+ export type RuntimeFallbackSignalTrustContext = {
39
+ trustPolicy: RuntimeFallbackSignalTrustPolicy;
40
+ runtimeState: RuntimeFallbackSignalRuntimeState;
41
+ };
42
+ export type RuntimeFallbackSignalConfig = {
43
+ endpoint: string;
44
+ gateName: string;
45
+ gateSnapshotStore: Promise<ContractGateSnapshotStore>;
46
+ failureHoldMs: number;
47
+ maxBodyBytes: number;
48
+ auth: RuntimeFallbackSignalAuthConfig;
49
+ trustPolicy: RuntimeFallbackSignalTrustPolicy;
50
+ runtimeState: RuntimeFallbackSignalRuntimeState;
51
+ };
52
+ export type RuntimeFallbackSignalSource = {
53
+ /**
54
+ * Server-trusted connection identity (socket remote address). Never derive
55
+ * request headers or payload: both are attacker-controlled and would let
56
+ * callers reset their own rate-limit budget.
57
+ */
58
+ remoteAddress?: string;
59
+ };
60
+ export declare function createRuntimeSignalError(message: string, code: RuntimeSignalError['code']): RuntimeSignalError;
61
+ export declare function getRuntimeSignalErrorStatusCode(signalError: RuntimeSignalError): 400 | 401 | 403 | 413 | 429 | 500;
62
+ export declare function normalizeRuntimeSignalOrigin(value: unknown): string | undefined;
63
+ export declare function normalizeRuntimeSignalAppName(payload: Record<string, unknown>): string;
64
+ export declare function normalizeRuntimeSignalRuntimeDigest(payload: Record<string, unknown>): string | undefined;
65
+ export declare function parseRuntimeFallbackSignalPayload(c: Context<ServerEnv>, maxBodyBytes: number): Promise<{
66
+ rawBody: string;
67
+ payload: Record<string, unknown>;
68
+ }>;
69
+ export declare function parseRuntimeFallbackSignalPayloadFromRawBody(rawBody: string, maxBodyBytes: number): Record<string, unknown>;
70
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { Context, ServerEnv } from '@modern-js/server-core';
2
+ import type { RuntimeFallbackSignalAuthConfig, RuntimeFallbackSignalConfig, RuntimeFallbackSignalSource, RuntimeFallbackSignalTrustContext, RuntimeFallbackSignalTrustPolicy } from './model';
3
+ export declare function resolveRuntimeFallbackSignalEndpoint(configuredEndpoint?: string): string;
4
+ export declare function normalizeRuntimeFallbackSignalAuthConfig(configured: {
5
+ enabled?: boolean;
6
+ headerName?: string;
7
+ expectedValue?: string;
8
+ expectedValueEnv?: string;
9
+ } | undefined): RuntimeFallbackSignalAuthConfig;
10
+ /**
11
+ * Normalizes auth config for the runtime fallback signal endpoint when the
12
+ * endpoint itself is enabled. The endpoint can persist failing contract gates
13
+ * (a canary kill switch), so it always requires a token.
14
+ */
15
+ export declare function normalizeRequiredRuntimeFallbackSignalAuthConfig(configured: Parameters<typeof normalizeRuntimeFallbackSignalAuthConfig>[0]): RuntimeFallbackSignalAuthConfig;
16
+ export declare function enforceRuntimeFallbackSignalAuthToken(token: string | undefined, authConfig: RuntimeFallbackSignalAuthConfig): void;
17
+ export declare function enforceRuntimeFallbackSignalAuth(c: Context<ServerEnv>, runtimeSignalConfig: RuntimeFallbackSignalConfig): void;
18
+ export declare function normalizeRuntimeFallbackTrustPolicy(configured: {
19
+ allowedApps?: string[];
20
+ allowedEntryOrigins?: string[];
21
+ expectedRuntimeDigests?: Record<string, string>;
22
+ enforceRuntimeDigest?: boolean;
23
+ maxSignalsPerWindow?: number;
24
+ windowMs?: number;
25
+ dedupeWindowMs?: number;
26
+ } | undefined): RuntimeFallbackSignalTrustPolicy;
27
+ export declare function enforceRuntimeFallbackSignalTrustPolicy(payload: Record<string, unknown>, runtimeSignalContext: RuntimeFallbackSignalTrustContext, source?: RuntimeFallbackSignalSource): {
28
+ deduped: boolean;
29
+ };
@@ -0,0 +1,4 @@
1
+ import type { RuntimeFallbackSignalConfig, RuntimeFallbackSignalRuntimeState, RuntimeFallbackSignalTrustPolicy } from './model';
2
+ export declare function createRuntimeFallbackSignalRuntimeState(): RuntimeFallbackSignalRuntimeState;
3
+ export declare function cleanupRuntimeFallbackSignalRuntimeState(now: number, runtimeState: RuntimeFallbackSignalRuntimeState, trustPolicy: RuntimeFallbackSignalTrustPolicy): void;
4
+ export declare function persistRuntimeFallbackContractGate(payload: Record<string, unknown>, runtimeSignalConfig: RuntimeFallbackSignalConfig): Promise<void>;
@@ -1,12 +1,12 @@
1
1
  import type { TelemetryCanaryContractGateStatus, TelemetryCanaryFailure } from './canary';
2
2
  import type { TelemetryQueueStats } from './registryTypes';
3
- export interface TelemetryCanaryHealthMetrics {
3
+ interface TelemetryCanaryHealthMetrics {
4
4
  queueStats: TelemetryQueueStats;
5
5
  unhealthyExporterCount: number;
6
6
  requiredContractGates: readonly string[];
7
7
  contractGates: ReadonlyMap<string, TelemetryCanaryContractGateStatus>;
8
8
  }
9
- export interface TelemetryCanaryHealthThresholds {
9
+ interface TelemetryCanaryHealthThresholds {
10
10
  maxQueueUtilization: number;
11
11
  maxTotalDropped: number;
12
12
  maxUnhealthyExporters: number;
@@ -17,3 +17,4 @@ export interface TelemetryCanaryHealthEvaluation {
17
17
  unhealthyExporterCount: number;
18
18
  }
19
19
  export declare const evaluateCanaryHealth: (metrics: TelemetryCanaryHealthMetrics, thresholds: TelemetryCanaryHealthThresholds) => TelemetryCanaryHealthEvaluation;
20
+ export {};
@@ -32,6 +32,16 @@ export interface TelemetryExporter {
32
32
  flush?: () => void | Promise<void>;
33
33
  shutdown?: () => void | Promise<void>;
34
34
  }
35
+ export type TelemetryEnvelopeBuilderContext = {
36
+ service: string;
37
+ module: string;
38
+ environment: string;
39
+ maxQueueSize: number;
40
+ };
41
+ export declare function buildDroppedEnvelope(context: TelemetryEnvelopeBuilderContext, droppedCount: number): TelemetryEnvelope;
42
+ export declare function buildQueueDepthEnvelope(context: TelemetryEnvelopeBuilderContext, queueDepth: number): TelemetryEnvelope;
43
+ export declare function buildQueueUtilizationEnvelope(context: TelemetryEnvelopeBuilderContext, queueDepth: number): TelemetryEnvelope;
44
+ export declare function buildStartupProbeEnvelope(context: TelemetryEnvelopeBuilderContext): TelemetryEnvelope;
35
45
  export declare function clamp(value: number, min: number, max: number): number;
36
46
  export declare function isRecord(value: unknown): value is Record<string, unknown>;
37
47
  export declare function redactObject(value: unknown, redactionKeys: Set<string>): Record<string, unknown> | undefined;
@@ -56,11 +56,8 @@ export declare class TelemetryRegistry {
56
56
  tags?: Record<string, string>;
57
57
  attributes?: Record<string, unknown>;
58
58
  }): void;
59
- private buildDroppedEnvelope;
60
- private buildQueueDepthEnvelope;
61
- private buildQueueUtilizationEnvelope;
59
+ private baseEnvelope;
62
60
  private emitBatch;
63
- private buildStartupProbeEnvelope;
64
61
  startupHealthCheck(options?: {
65
62
  failLoud?: boolean;
66
63
  }): Promise<void>;
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.5.0-ultramodern.36",
20
+ "version": "3.5.0-ultramodern.38",
21
21
  "types": "./dist/types/index.d.ts",
22
22
  "main": "./dist/cjs/index.js",
23
23
  "exports": {
@@ -44,17 +44,17 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@swc/helpers": "^0.5.23",
47
- "@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.5.0-ultramodern.36",
48
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.36",
49
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.36",
50
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.36"
47
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.38",
48
+ "@modern-js/create-request": "npm:@bleedingdev/modern-js-create-request@3.5.0-ultramodern.38",
49
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.38",
50
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.38"
51
51
  },
52
52
  "devDependencies": {
53
- "@rslib/core": "0.23.1",
54
- "@types/node": "^26.0.1",
55
- "@typescript/native-preview": "7.0.0-dev.20260628.1",
56
- "@scripts/rstest-config": "2.66.0",
57
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.36"
53
+ "@rslib/core": "0.23.2",
54
+ "@types/node": "^26.1.1",
55
+ "@typescript/native-preview": "7.0.0-dev.20260707.2",
56
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.38",
57
+ "@scripts/rstest-config": "2.66.0"
58
58
  },
59
59
  "sideEffects": false,
60
60
  "publishConfig": {