@bleedingdev/modern-js-server-runtime-extensions 3.5.0-ultramodern.1 → 3.5.0-ultramodern.100

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 (179) hide show
  1. package/dist/cjs/contract-gate-snapshot-normalization.js +122 -0
  2. package/dist/cjs/contract-gate-snapshot-store/file-store.js +102 -0
  3. package/dist/cjs/contract-gate-snapshot-store/http-store.js +133 -0
  4. package/dist/cjs/contract-gate-snapshot-store/index.js +58 -0
  5. package/dist/cjs/contract-gate-snapshot-store/resolve.js +124 -0
  6. package/dist/cjs/contract-gate-snapshot-store/types.js +44 -0
  7. package/dist/cjs/contractGateAutopilot.js +22 -70
  8. package/dist/cjs/index.js +6 -25
  9. package/dist/cjs/mfCache.js +2 -2
  10. package/dist/cjs/module-federation-css/collector.js +79 -0
  11. package/dist/cjs/module-federation-css/index.js +55 -0
  12. package/dist/cjs/module-federation-css/manifest.js +129 -0
  13. package/dist/cjs/module-federation-css/plugin.js +71 -0
  14. package/dist/cjs/module-federation-css/remote.js +133 -0
  15. package/dist/cjs/runtime-fallback-signal/index.js +93 -0
  16. package/dist/cjs/runtime-fallback-signal/model.js +157 -0
  17. package/dist/cjs/runtime-fallback-signal/resolver.js +163 -0
  18. package/dist/cjs/runtime-fallback-signal/store.js +83 -0
  19. package/dist/cjs/runtimeFallbackSignal.js +32 -281
  20. package/dist/cjs/telemetry/canary.js +180 -0
  21. package/dist/cjs/telemetry/canaryEvaluation.js +79 -0
  22. package/dist/cjs/telemetry/canarySetup.js +107 -0
  23. package/dist/cjs/telemetry/envelope.js +223 -0
  24. package/dist/cjs/telemetry/exporters.js +148 -0
  25. package/dist/cjs/telemetry/lifecycle.js +98 -0
  26. package/dist/cjs/telemetry/metrics.js +115 -0
  27. package/dist/cjs/telemetry/plugin.js +185 -0
  28. package/dist/cjs/telemetry/registry.js +296 -0
  29. package/dist/cjs/telemetry/registryTypes.js +46 -0
  30. package/dist/cjs/telemetry/runtimeEndpoints.js +135 -0
  31. package/dist/cjs/telemetry.js +32 -343
  32. package/dist/cjs/telemetryCore.js +14 -767
  33. package/dist/esm/contract-gate-snapshot-normalization.mjs +81 -0
  34. package/dist/esm/contract-gate-snapshot-store/file-store.mjs +51 -0
  35. package/dist/esm/contract-gate-snapshot-store/http-store.mjs +92 -0
  36. package/dist/esm/contract-gate-snapshot-store/index.mjs +4 -0
  37. package/dist/esm/contract-gate-snapshot-store/resolve.mjs +70 -0
  38. package/dist/esm/contract-gate-snapshot-store/types.mjs +3 -0
  39. package/dist/esm/contractGateAutopilot.mjs +21 -69
  40. package/dist/esm/index.mjs +1 -2
  41. package/dist/esm/mfCache.mjs +2 -2
  42. package/dist/esm/module-federation-css/collector.mjs +38 -0
  43. package/dist/esm/module-federation-css/index.mjs +4 -0
  44. package/dist/esm/module-federation-css/manifest.mjs +69 -0
  45. package/dist/esm/module-federation-css/plugin.mjs +33 -0
  46. package/dist/esm/module-federation-css/remote.mjs +92 -0
  47. package/dist/esm/runtime-fallback-signal/index.mjs +3 -0
  48. package/dist/esm/runtime-fallback-signal/model.mjs +73 -0
  49. package/dist/esm/runtime-fallback-signal/resolver.mjs +107 -0
  50. package/dist/esm/runtime-fallback-signal/store.mjs +39 -0
  51. package/dist/esm/runtimeFallbackSignal.mjs +1 -222
  52. package/dist/esm/telemetry/canary.mjs +142 -0
  53. package/dist/esm/telemetry/canaryEvaluation.mjs +41 -0
  54. package/dist/esm/telemetry/canarySetup.mjs +69 -0
  55. package/dist/esm/telemetry/envelope.mjs +164 -0
  56. package/dist/esm/telemetry/exporters.mjs +104 -0
  57. package/dist/esm/telemetry/lifecycle.mjs +60 -0
  58. package/dist/esm/telemetry/metrics.mjs +77 -0
  59. package/dist/esm/telemetry/plugin.mjs +87 -0
  60. package/dist/esm/telemetry/registry.mjs +258 -0
  61. package/dist/esm/telemetry/registryTypes.mjs +8 -0
  62. package/dist/esm/telemetry/runtimeEndpoints.mjs +94 -0
  63. package/dist/esm/telemetry.mjs +1 -275
  64. package/dist/esm/telemetryCore.mjs +6 -759
  65. package/dist/esm-node/contract-gate-snapshot-normalization.mjs +82 -0
  66. package/dist/esm-node/contract-gate-snapshot-store/file-store.mjs +52 -0
  67. package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +93 -0
  68. package/dist/esm-node/contract-gate-snapshot-store/index.mjs +5 -0
  69. package/dist/esm-node/contract-gate-snapshot-store/resolve.mjs +71 -0
  70. package/dist/esm-node/contract-gate-snapshot-store/types.mjs +4 -0
  71. package/dist/esm-node/contractGateAutopilot.mjs +21 -69
  72. package/dist/esm-node/index.mjs +1 -2
  73. package/dist/esm-node/mfCache.mjs +2 -2
  74. package/dist/esm-node/module-federation-css/collector.mjs +39 -0
  75. package/dist/esm-node/module-federation-css/index.mjs +5 -0
  76. package/dist/esm-node/module-federation-css/manifest.mjs +70 -0
  77. package/dist/esm-node/module-federation-css/plugin.mjs +34 -0
  78. package/dist/esm-node/module-federation-css/remote.mjs +93 -0
  79. package/dist/esm-node/runtime-fallback-signal/index.mjs +4 -0
  80. package/dist/esm-node/runtime-fallback-signal/model.mjs +74 -0
  81. package/dist/esm-node/runtime-fallback-signal/resolver.mjs +108 -0
  82. package/dist/esm-node/runtime-fallback-signal/store.mjs +40 -0
  83. package/dist/esm-node/runtimeFallbackSignal.mjs +1 -222
  84. package/dist/esm-node/telemetry/canary.mjs +143 -0
  85. package/dist/esm-node/telemetry/canaryEvaluation.mjs +42 -0
  86. package/dist/esm-node/telemetry/canarySetup.mjs +70 -0
  87. package/dist/esm-node/telemetry/envelope.mjs +165 -0
  88. package/dist/esm-node/telemetry/exporters.mjs +105 -0
  89. package/dist/esm-node/telemetry/lifecycle.mjs +61 -0
  90. package/dist/esm-node/telemetry/metrics.mjs +78 -0
  91. package/dist/esm-node/telemetry/plugin.mjs +88 -0
  92. package/dist/esm-node/telemetry/registry.mjs +259 -0
  93. package/dist/esm-node/telemetry/registryTypes.mjs +9 -0
  94. package/dist/esm-node/telemetry/runtimeEndpoints.mjs +95 -0
  95. package/dist/esm-node/telemetry.mjs +1 -275
  96. package/dist/esm-node/telemetryCore.mjs +6 -759
  97. package/dist/types/contract-gate-snapshot-normalization.d.ts +15 -0
  98. package/dist/types/contract-gate-snapshot-store/file-store.d.ts +3 -0
  99. package/dist/types/contract-gate-snapshot-store/http-store.d.ts +5 -0
  100. package/dist/types/contract-gate-snapshot-store/index.d.ts +5 -0
  101. package/dist/types/contract-gate-snapshot-store/resolve.d.ts +9 -0
  102. package/dist/types/{contractGateSnapshotStore.d.ts → contract-gate-snapshot-store/types.d.ts} +1 -11
  103. package/dist/types/contractGateAutopilot.d.ts +3 -6
  104. package/dist/types/index.d.ts +1 -2
  105. package/dist/types/module-federation-css/collector.d.ts +25 -0
  106. package/dist/types/module-federation-css/index.d.ts +8 -0
  107. package/dist/types/module-federation-css/manifest.d.ts +28 -0
  108. package/dist/types/module-federation-css/plugin.d.ts +23 -0
  109. package/dist/types/module-federation-css/remote.d.ts +20 -0
  110. package/dist/types/runtime-fallback-signal/index.d.ts +4 -0
  111. package/dist/types/runtime-fallback-signal/model.d.ts +70 -0
  112. package/dist/types/runtime-fallback-signal/resolver.d.ts +29 -0
  113. package/dist/types/runtime-fallback-signal/store.d.ts +4 -0
  114. package/dist/types/runtimeFallbackSignal.d.ts +1 -94
  115. package/dist/types/telemetry/canary.d.ts +85 -0
  116. package/dist/types/telemetry/canaryEvaluation.d.ts +20 -0
  117. package/dist/types/telemetry/canarySetup.d.ts +17 -0
  118. package/dist/types/telemetry/envelope.d.ts +55 -0
  119. package/dist/types/telemetry/exporters.d.ts +12 -0
  120. package/dist/types/telemetry/lifecycle.d.ts +18 -0
  121. package/dist/types/telemetry/metrics.d.ts +3 -0
  122. package/dist/types/telemetry/plugin.d.ts +12 -0
  123. package/dist/types/telemetry/registry.d.ts +69 -0
  124. package/dist/types/telemetry/registryTypes.d.ts +50 -0
  125. package/dist/types/telemetry/runtimeEndpoints.d.ts +35 -0
  126. package/dist/types/telemetry.d.ts +1 -12
  127. package/dist/types/telemetryCore.d.ts +6 -257
  128. package/package.json +10 -12
  129. package/src/contract-gate-snapshot-normalization.ts +155 -0
  130. package/src/contract-gate-snapshot-store/file-store.ts +83 -0
  131. package/src/contract-gate-snapshot-store/http-store.ts +159 -0
  132. package/src/contract-gate-snapshot-store/index.ts +20 -0
  133. package/src/contract-gate-snapshot-store/resolve.ts +179 -0
  134. package/src/contract-gate-snapshot-store/types.ts +64 -0
  135. package/src/contractGateAutopilot.ts +39 -131
  136. package/src/index.ts +1 -17
  137. package/src/mfCache.ts +3 -1
  138. package/src/module-federation-css/collector.ts +82 -0
  139. package/src/module-federation-css/index.ts +14 -0
  140. package/src/module-federation-css/manifest.ts +163 -0
  141. package/src/module-federation-css/plugin.ts +86 -0
  142. package/src/module-federation-css/remote.ts +165 -0
  143. package/src/runtime-fallback-signal/index.ts +34 -0
  144. package/src/runtime-fallback-signal/model.ts +230 -0
  145. package/src/runtime-fallback-signal/resolver.ts +304 -0
  146. package/src/runtime-fallback-signal/store.ts +78 -0
  147. package/src/runtimeFallbackSignal.ts +1 -584
  148. package/src/telemetry/canary.ts +291 -0
  149. package/src/telemetry/canaryEvaluation.ts +83 -0
  150. package/src/telemetry/canarySetup.ts +160 -0
  151. package/src/telemetry/envelope.ts +277 -0
  152. package/src/telemetry/exporters.ts +165 -0
  153. package/src/telemetry/lifecycle.ts +138 -0
  154. package/src/telemetry/metrics.ts +141 -0
  155. package/src/telemetry/plugin.ts +197 -0
  156. package/src/telemetry/registry.ts +424 -0
  157. package/src/telemetry/registryTypes.ts +63 -0
  158. package/src/telemetry/runtimeEndpoints.ts +172 -0
  159. package/src/telemetry.ts +1 -554
  160. package/src/telemetryCore.ts +34 -1332
  161. package/tests/contractGateAutopilot.test.ts +205 -0
  162. package/tests/contractGateSnapshotStore.test.ts +54 -1
  163. package/tests/helpers.ts +1 -0
  164. package/tests/moduleFederationCss.test.ts +1 -1
  165. package/tests/registration.test.ts +1 -1
  166. package/tests/telemetry.test.ts +51 -0
  167. package/tests/telemetryAutopilot.test.ts +141 -0
  168. package/tests/telemetryCanaryOrchestrator.test.ts +225 -0
  169. package/tests/telemetryLifecycle.test.ts +253 -2
  170. package/tests/telemetryRegistryQueueMatrix.test.ts +227 -0
  171. package/dist/cjs/contractGateSnapshotStore.js +0 -253
  172. package/dist/cjs/moduleFederationCss.js +0 -285
  173. package/dist/esm/contractGateSnapshotStore.mjs +0 -190
  174. package/dist/esm/moduleFederationCss.mjs +0 -225
  175. package/dist/esm-node/contractGateSnapshotStore.mjs +0 -192
  176. package/dist/esm-node/moduleFederationCss.mjs +0 -226
  177. package/dist/types/moduleFederationCss.d.ts +0 -87
  178. package/src/contractGateSnapshotStore.ts +0 -420
  179. package/src/moduleFederationCss.ts +0 -473
@@ -1,5 +1,28 @@
1
1
  "use strict";
2
- var __webpack_require__ = {};
2
+ var __webpack_modules__ = {
3
+ "./runtime-fallback-signal" (module) {
4
+ module.exports = require("./runtime-fallback-signal/index.js");
5
+ }
6
+ };
7
+ var __webpack_module_cache__ = {};
8
+ function __webpack_require__(moduleId) {
9
+ var cachedModule = __webpack_module_cache__[moduleId];
10
+ if (void 0 !== cachedModule) return cachedModule.exports;
11
+ var module = __webpack_module_cache__[moduleId] = {
12
+ exports: {}
13
+ };
14
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
15
+ return module.exports;
16
+ }
17
+ (()=>{
18
+ __webpack_require__.n = (module)=>{
19
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
20
+ __webpack_require__.d(getter, {
21
+ a: getter
22
+ });
23
+ return getter;
24
+ };
25
+ })();
3
26
  (()=>{
4
27
  __webpack_require__.d = (exports1, getters, values)=>{
5
28
  var define = (defs, kind)=>{
@@ -26,286 +49,14 @@ var __webpack_require__ = {};
26
49
  };
27
50
  })();
28
51
  var __webpack_exports__ = {};
29
- __webpack_require__.r(__webpack_exports__);
30
- __webpack_require__.d(__webpack_exports__, {
31
- DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS: ()=>DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS,
32
- DEFAULT_RUNTIME_FALLBACK_GATE_NAME: ()=>DEFAULT_RUNTIME_FALLBACK_GATE_NAME,
33
- DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES: ()=>DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES,
34
- DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT: ()=>DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT,
35
- DEFAULT_RUNTIME_STATUS_ENDPOINT: ()=>DEFAULT_RUNTIME_STATUS_ENDPOINT,
36
- createRuntimeFallbackSignalRuntimeState: ()=>createRuntimeFallbackSignalRuntimeState,
37
- createRuntimeSignalError: ()=>createRuntimeSignalError,
38
- enforceRuntimeFallbackSignalAuth: ()=>enforceRuntimeFallbackSignalAuth,
39
- enforceRuntimeFallbackSignalAuthToken: ()=>enforceRuntimeFallbackSignalAuthToken,
40
- enforceRuntimeFallbackSignalTrustPolicy: ()=>enforceRuntimeFallbackSignalTrustPolicy,
41
- getRuntimeSignalErrorStatusCode: ()=>getRuntimeSignalErrorStatusCode,
42
- normalizeRequiredRuntimeFallbackSignalAuthConfig: ()=>normalizeRequiredRuntimeFallbackSignalAuthConfig,
43
- normalizeRuntimeFallbackSignalAuthConfig: ()=>normalizeRuntimeFallbackSignalAuthConfig,
44
- normalizeRuntimeFallbackTrustPolicy: ()=>normalizeRuntimeFallbackTrustPolicy,
45
- parseRuntimeFallbackSignalPayload: ()=>parseRuntimeFallbackSignalPayload,
46
- parseRuntimeFallbackSignalPayloadFromRawBody: ()=>parseRuntimeFallbackSignalPayloadFromRawBody,
47
- persistRuntimeFallbackContractGate: ()=>persistRuntimeFallbackContractGate,
48
- resolveRuntimeFallbackSignalEndpoint: ()=>resolveRuntimeFallbackSignalEndpoint
49
- });
50
- const external_node_crypto_namespaceObject = require("node:crypto");
51
- const external_contractGateSnapshotStore_js_namespaceObject = require("./contractGateSnapshotStore.js");
52
- const DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = '/_modern/contract-gates/runtime-fallback';
53
- const DEFAULT_RUNTIME_STATUS_ENDPOINT = '/_modern/runtime/status';
54
- const DEFAULT_RUNTIME_FALLBACK_GATE_NAME = 'runtime-mf-fallback-health';
55
- const DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS = 300000;
56
- const DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES = 16384;
57
- const DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER = 'x-modernjs-runtime-signal-token';
58
- const DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW = 30;
59
- const DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS = 60000;
60
- const DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS = 10000;
61
- function resolveRuntimeFallbackSignalEndpoint(configuredEndpoint) {
62
- const rawEndpoint = configuredEndpoint?.trim();
63
- if (!rawEndpoint) return DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT;
64
- if (rawEndpoint.startsWith('/')) return rawEndpoint;
65
- try {
66
- return new URL(rawEndpoint).pathname || DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT;
67
- } catch (_error) {
68
- return `/${rawEndpoint.replace(/^\/+/, '')}`;
69
- }
70
- }
71
- function createRuntimeSignalError(message, code) {
72
- const error = new Error(message);
73
- error.code = code;
74
- return error;
75
- }
76
- function getUtf8ByteLength(input) {
77
- if ("u" > typeof Buffer) return Buffer.byteLength(input);
78
- return new TextEncoder().encode(input).length;
79
- }
80
- function normalizeRuntimeSignalOrigin(value) {
81
- if ('string' != typeof value || 0 === value.trim().length) return;
82
- try {
83
- return new URL(value).origin;
84
- } catch (_error) {
85
- return;
86
- }
87
- }
88
- function normalizeRuntimeSignalAppName(payload) {
89
- if ('string' != typeof payload.appName) return 'unknown';
90
- const normalized = payload.appName.trim();
91
- return normalized.length > 0 ? normalized : 'unknown';
92
- }
93
- function normalizeRuntimeSignalRuntimeDigest(payload) {
94
- if ('string' == typeof payload.runtimeDigest && payload.runtimeDigest.trim()) return payload.runtimeDigest.trim();
95
- const metadata = payload.metadata;
96
- if (metadata && 'object' == typeof metadata && !Array.isArray(metadata) && 'string' == typeof metadata.runtimeDigest) {
97
- const digest = String(metadata.runtimeDigest).trim();
98
- if (digest) return digest;
99
- }
100
- }
101
- function normalizeRuntimeFallbackSignalAuthConfig(configured) {
102
- const headerName = 'string' == typeof configured?.headerName && configured.headerName.trim() ? configured.headerName.trim().toLowerCase() : DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER;
103
- const expectedFromEnv = 'string' == typeof configured?.expectedValueEnv && configured.expectedValueEnv.trim().length > 0 ? process.env[configured.expectedValueEnv.trim()] : void 0;
104
- const expectedFromConfig = 'string' == typeof configured?.expectedValue && configured.expectedValue.trim().length > 0 ? configured.expectedValue.trim() : void 0;
105
- const expectedValue = expectedFromConfig || expectedFromEnv;
106
- const enabled = configured?.enabled === true;
107
- if (enabled && !expectedValue) throw new Error('[telemetry.canary.autopilot.runtimeFallbackSignal] auth.enabled is true but no expected token is configured');
108
- return {
109
- enabled,
110
- headerName,
111
- expectedValue
112
- };
113
- }
114
- function normalizeRequiredRuntimeFallbackSignalAuthConfig(configured) {
115
- if (configured?.enabled === false) throw new Error('[telemetry.canary.autopilot.runtimeFallbackSignal] the endpoint cannot be enabled with auth disabled; configure auth.expectedValue or auth.expectedValueEnv');
116
- try {
117
- return normalizeRuntimeFallbackSignalAuthConfig({
118
- ...configured,
119
- enabled: true
120
- });
121
- } catch (_error) {
122
- throw new Error('[telemetry.canary.autopilot.runtimeFallbackSignal] enabling the endpoint requires an auth token; configure auth.expectedValue or auth.expectedValueEnv');
123
- }
124
- }
125
- function safeTokenEquals(candidate, expected) {
126
- const candidateDigest = (0, external_node_crypto_namespaceObject.createHash)('sha256').update(candidate).digest();
127
- const expectedDigest = (0, external_node_crypto_namespaceObject.createHash)('sha256').update(expected).digest();
128
- return (0, external_node_crypto_namespaceObject.timingSafeEqual)(candidateDigest, expectedDigest);
129
- }
130
- function enforceRuntimeFallbackSignalAuthToken(token, authConfig) {
131
- if (!authConfig.enabled) return;
132
- if (!token || !authConfig.expectedValue || !safeTokenEquals(token, authConfig.expectedValue)) throw createRuntimeSignalError('runtime fallback signal auth failed', 'UNAUTHORIZED');
133
- }
134
- function enforceRuntimeFallbackSignalAuth(c, runtimeSignalConfig) {
135
- enforceRuntimeFallbackSignalAuthToken(c.req.header(runtimeSignalConfig.auth.headerName), runtimeSignalConfig.auth);
136
- }
137
- function normalizeRuntimeFallbackTrustPolicy(configured) {
138
- const allowedApps = Array.isArray(configured?.allowedApps) ? configured.allowedApps.map((item)=>'string' == typeof item ? item.trim() : '').filter(Boolean) : [];
139
- const allowedEntryOrigins = Array.isArray(configured?.allowedEntryOrigins) ? configured.allowedEntryOrigins.map((item)=>normalizeRuntimeSignalOrigin(item)).filter((item)=>Boolean(item)) : [];
140
- const expectedRuntimeDigestsRaw = configured?.expectedRuntimeDigests || {};
141
- const expectedRuntimeDigests = {};
142
- Object.entries(expectedRuntimeDigestsRaw).forEach(([appName, digest])=>{
143
- if ('string' == typeof appName && appName.trim().length > 0 && 'string' == typeof digest && digest.trim().length > 0) expectedRuntimeDigests[appName.trim()] = digest.trim();
144
- });
145
- return {
146
- allowedApps,
147
- allowedEntryOrigins,
148
- expectedRuntimeDigests,
149
- enforceRuntimeDigest: configured?.enforceRuntimeDigest === true,
150
- maxSignalsPerWindow: Math.max(1, Math.floor(configured?.maxSignalsPerWindow ?? DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW)),
151
- windowMs: Math.max(1000, Math.floor(configured?.windowMs ?? DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS)),
152
- dedupeWindowMs: Math.max(0, Math.floor(configured?.dedupeWindowMs ?? DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS))
153
- };
154
- }
155
- function createRuntimeFallbackSignalRuntimeState() {
156
- return {
157
- rateLimitBySource: new Map(),
158
- dedupeByFingerprint: new Map()
159
- };
160
- }
161
- function cleanupRuntimeFallbackSignalRuntimeState(now, runtimeState, trustPolicy) {
162
- const dedupeExpiryMs = Math.max(trustPolicy.dedupeWindowMs, trustPolicy.windowMs, 1000);
163
- runtimeState.dedupeByFingerprint.forEach((lastSeenAt, fingerprint)=>{
164
- if (now - lastSeenAt > dedupeExpiryMs) runtimeState.dedupeByFingerprint.delete(fingerprint);
165
- });
166
- runtimeState.rateLimitBySource.forEach((state, source)=>{
167
- if (now - state.windowStartedAt > 2 * trustPolicy.windowMs) runtimeState.rateLimitBySource.delete(source);
168
- });
169
- }
170
- function enforceRuntimeFallbackSignalTrustPolicy(payload, runtimeSignalContext, source = {}) {
171
- const { trustPolicy, runtimeState } = runtimeSignalContext;
172
- const now = Date.now();
173
- cleanupRuntimeFallbackSignalRuntimeState(now, runtimeState, trustPolicy);
174
- const appName = normalizeRuntimeSignalAppName(payload);
175
- const entryOrigin = normalizeRuntimeSignalOrigin(payload.entry);
176
- const runtimeDigest = normalizeRuntimeSignalRuntimeDigest(payload);
177
- if (trustPolicy.allowedApps.length > 0 && !trustPolicy.allowedApps.includes(appName)) throw createRuntimeSignalError(`runtime fallback signal app "${appName}" is not trusted`, 'UNTRUSTED_SOURCE');
178
- if (trustPolicy.allowedEntryOrigins.length > 0) {
179
- if (!entryOrigin || !trustPolicy.allowedEntryOrigins.includes(entryOrigin)) throw createRuntimeSignalError(`runtime fallback signal entry origin "${entryOrigin || 'unknown'}" is not trusted`, 'UNTRUSTED_SOURCE');
180
- }
181
- const expectedDigest = trustPolicy.expectedRuntimeDigests[appName];
182
- if (expectedDigest && runtimeDigest !== expectedDigest) throw createRuntimeSignalError(`runtime fallback runtimeDigest mismatch for app "${appName}"`, 'UNTRUSTED_SOURCE');
183
- if (trustPolicy.enforceRuntimeDigest && !runtimeDigest) throw createRuntimeSignalError(`runtime fallback signal for app "${appName}" is missing runtimeDigest`, 'UNTRUSTED_SOURCE');
184
- const dedupeFingerprint = JSON.stringify({
185
- appName,
186
- entryOrigin: entryOrigin || 'unknown',
187
- reason: payload.reason || 'runtime_fallback',
188
- phase: payload.phase || 'unknown',
189
- runtimeDigest: runtimeDigest || 'unknown'
190
- });
191
- const dedupeWindowMs = trustPolicy.dedupeWindowMs;
192
- if (dedupeWindowMs > 0) {
193
- const lastSeenAt = runtimeState.dedupeByFingerprint.get(dedupeFingerprint);
194
- runtimeState.dedupeByFingerprint.set(dedupeFingerprint, now);
195
- if ('number' == typeof lastSeenAt && now - lastSeenAt <= dedupeWindowMs) return {
196
- deduped: true
197
- };
198
- } else runtimeState.dedupeByFingerprint.set(dedupeFingerprint, now);
199
- const remoteAddress = source.remoteAddress?.trim();
200
- const sourceKey = remoteAddress || 'unknown-remote';
201
- const rateState = runtimeState.rateLimitBySource.get(sourceKey);
202
- if (!rateState || now - rateState.windowStartedAt > trustPolicy.windowMs) runtimeState.rateLimitBySource.set(sourceKey, {
203
- count: 1,
204
- windowStartedAt: now
205
- });
206
- else {
207
- if (rateState.count >= trustPolicy.maxSignalsPerWindow) throw createRuntimeSignalError(`runtime fallback signal rate-limited for source "${sourceKey}"`, 'RATE_LIMITED');
208
- rateState.count += 1;
209
- }
210
- return {
211
- deduped: false
212
- };
213
- }
214
- async function parseRuntimeFallbackSignalPayload(c, maxBodyBytes) {
215
- const contentLengthHeader = c.req.header('content-length');
216
- if (contentLengthHeader) {
217
- const contentLength = Number.parseInt(contentLengthHeader, 10);
218
- if (Number.isFinite(contentLength) && contentLength > maxBodyBytes) throw createRuntimeSignalError('runtime fallback signal payload too large', 'PAYLOAD_TOO_LARGE');
219
- }
220
- const rawBody = await c.req.raw.text();
221
- const payload = parseRuntimeFallbackSignalPayloadFromRawBody(rawBody, maxBodyBytes);
222
- return {
223
- rawBody,
224
- payload
225
- };
226
- }
227
- function parseRuntimeFallbackSignalPayloadFromRawBody(rawBody, maxBodyBytes) {
228
- if (!rawBody || 0 === rawBody.trim().length) throw createRuntimeSignalError('runtime fallback signal body is empty', 'INVALID_PAYLOAD');
229
- if (getUtf8ByteLength(rawBody) > maxBodyBytes) throw createRuntimeSignalError('runtime fallback signal payload too large', 'PAYLOAD_TOO_LARGE');
230
- let payload;
231
- try {
232
- payload = JSON.parse(rawBody);
233
- } catch (_error) {
234
- throw createRuntimeSignalError('runtime fallback signal body must be valid JSON', 'INVALID_PAYLOAD');
235
- }
236
- if (!payload || 'object' != typeof payload || Array.isArray(payload)) throw createRuntimeSignalError('runtime fallback signal body must be a JSON object', 'INVALID_PAYLOAD');
237
- return payload;
238
- }
239
- function getRuntimeSignalErrorStatusCode(signalError) {
240
- if ('PAYLOAD_TOO_LARGE' === signalError.code) return 413;
241
- if ('INVALID_PAYLOAD' === signalError.code) return 400;
242
- if ('UNAUTHORIZED' === signalError.code) return 401;
243
- if ('RATE_LIMITED' === signalError.code) return 429;
244
- if ('UNTRUSTED_SOURCE' === signalError.code) return 403;
245
- return 500;
246
- }
247
- async function persistRuntimeFallbackContractGate(payload, runtimeSignalConfig) {
248
- const now = Date.now();
249
- const gateSnapshotStore = await runtimeSignalConfig.gateSnapshotStore;
250
- const snapshot = await gateSnapshotStore.readSnapshot() || {};
251
- const existingGates = snapshot.gates && 'object' == typeof snapshot.gates ? snapshot.gates : {};
252
- const reason = 'string' == typeof payload.reason ? payload.reason : 'runtime_fallback';
253
- const phase = 'string' == typeof payload.phase ? payload.phase : 'unknown';
254
- const appName = 'string' == typeof payload.appName ? payload.appName : 'unknown';
255
- const entry = 'string' == typeof payload.entry ? payload.entry : void 0;
256
- snapshot.schemaVersion = 'number' == typeof snapshot.schemaVersion ? snapshot.schemaVersion : external_contractGateSnapshotStore_js_namespaceObject.CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION;
257
- snapshot.updatedAt = now;
258
- snapshot.gates = {
259
- ...existingGates,
260
- [runtimeSignalConfig.gateName]: {
261
- passed: false,
262
- reason: `runtime_fallback:${reason} phase=${phase} app=${appName}${entry ? ` entry=${entry}` : ''}`,
263
- updatedAt: now,
264
- expiresAt: now + runtimeSignalConfig.failureHoldMs,
265
- source: 'runtime-mf-fallback-signal',
266
- metadata: payload
267
- }
268
- };
269
- await gateSnapshotStore.writeSnapshot(snapshot);
270
- }
271
- exports.DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS;
272
- exports.DEFAULT_RUNTIME_FALLBACK_GATE_NAME = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_GATE_NAME;
273
- exports.DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES;
274
- exports.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT;
275
- exports.DEFAULT_RUNTIME_STATUS_ENDPOINT = __webpack_exports__.DEFAULT_RUNTIME_STATUS_ENDPOINT;
276
- exports.createRuntimeFallbackSignalRuntimeState = __webpack_exports__.createRuntimeFallbackSignalRuntimeState;
277
- exports.createRuntimeSignalError = __webpack_exports__.createRuntimeSignalError;
278
- exports.enforceRuntimeFallbackSignalAuth = __webpack_exports__.enforceRuntimeFallbackSignalAuth;
279
- exports.enforceRuntimeFallbackSignalAuthToken = __webpack_exports__.enforceRuntimeFallbackSignalAuthToken;
280
- exports.enforceRuntimeFallbackSignalTrustPolicy = __webpack_exports__.enforceRuntimeFallbackSignalTrustPolicy;
281
- exports.getRuntimeSignalErrorStatusCode = __webpack_exports__.getRuntimeSignalErrorStatusCode;
282
- exports.normalizeRequiredRuntimeFallbackSignalAuthConfig = __webpack_exports__.normalizeRequiredRuntimeFallbackSignalAuthConfig;
283
- exports.normalizeRuntimeFallbackSignalAuthConfig = __webpack_exports__.normalizeRuntimeFallbackSignalAuthConfig;
284
- exports.normalizeRuntimeFallbackTrustPolicy = __webpack_exports__.normalizeRuntimeFallbackTrustPolicy;
285
- exports.parseRuntimeFallbackSignalPayload = __webpack_exports__.parseRuntimeFallbackSignalPayload;
286
- exports.parseRuntimeFallbackSignalPayloadFromRawBody = __webpack_exports__.parseRuntimeFallbackSignalPayloadFromRawBody;
287
- exports.persistRuntimeFallbackContractGate = __webpack_exports__.persistRuntimeFallbackContractGate;
288
- exports.resolveRuntimeFallbackSignalEndpoint = __webpack_exports__.resolveRuntimeFallbackSignalEndpoint;
289
- for(var __rspack_i in __webpack_exports__)if (-1 === [
290
- "DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS",
291
- "DEFAULT_RUNTIME_FALLBACK_GATE_NAME",
292
- "DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES",
293
- "DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT",
294
- "DEFAULT_RUNTIME_STATUS_ENDPOINT",
295
- "createRuntimeFallbackSignalRuntimeState",
296
- "createRuntimeSignalError",
297
- "enforceRuntimeFallbackSignalAuth",
298
- "enforceRuntimeFallbackSignalAuthToken",
299
- "enforceRuntimeFallbackSignalTrustPolicy",
300
- "getRuntimeSignalErrorStatusCode",
301
- "normalizeRequiredRuntimeFallbackSignalAuthConfig",
302
- "normalizeRuntimeFallbackSignalAuthConfig",
303
- "normalizeRuntimeFallbackTrustPolicy",
304
- "parseRuntimeFallbackSignalPayload",
305
- "parseRuntimeFallbackSignalPayloadFromRawBody",
306
- "persistRuntimeFallbackContractGate",
307
- "resolveRuntimeFallbackSignalEndpoint"
308
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
52
+ (()=>{
53
+ __webpack_require__.r(__webpack_exports__);
54
+ var _runtime_fallback_signal__rspack_import_0 = __webpack_require__("./runtime-fallback-signal");
55
+ var __rspack_reexport = {};
56
+ for(const __rspack_import_key in _runtime_fallback_signal__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_runtime_fallback_signal__rspack_import_0[__rspack_import_key];
57
+ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
58
+ })();
59
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
309
60
  Object.defineProperty(exports, '__esModule', {
310
61
  value: true
311
62
  });
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ TelemetryCanaryOrchestrator: ()=>TelemetryCanaryOrchestrator
32
+ });
33
+ const external_canaryEvaluation_js_namespaceObject = require("./canaryEvaluation.js");
34
+ const external_envelope_js_namespaceObject = require("./envelope.js");
35
+ class TelemetryCanaryOrchestrator {
36
+ setRequiredContractGates(gates) {
37
+ this.requiredContractGates = Array.from(new Set(gates.map((item)=>item.trim()).filter(Boolean)));
38
+ }
39
+ addRequiredContractGate(name) {
40
+ const normalizedName = name.trim();
41
+ if (!normalizedName) return;
42
+ if (!this.requiredContractGates.includes(normalizedName)) this.requiredContractGates.push(normalizedName);
43
+ }
44
+ setContractGate(name, passed, reason) {
45
+ this.contractGates.set(name, {
46
+ name,
47
+ passed,
48
+ reason,
49
+ updatedAt: Date.now()
50
+ });
51
+ }
52
+ setContractGates(gates) {
53
+ for (const [name, value] of Object.entries(gates)){
54
+ if ('boolean' == typeof value) {
55
+ this.setContractGate(name, value);
56
+ continue;
57
+ }
58
+ this.setContractGate(name, value.passed, value.reason);
59
+ }
60
+ }
61
+ resetToCanary() {
62
+ this.state = 'canary';
63
+ this.consecutiveHealthy = 0;
64
+ this.consecutiveFailures = 0;
65
+ }
66
+ collectFailures() {
67
+ const queueStats = this.registry.getQueueStats();
68
+ const unhealthyExporterCount = this.registry.getExporterHealth().filter((item)=>!item.healthy).length;
69
+ return (0, external_canaryEvaluation_js_namespaceObject.evaluateCanaryHealth)({
70
+ queueStats,
71
+ unhealthyExporterCount,
72
+ requiredContractGates: this.requiredContractGates,
73
+ contractGates: this.contractGates
74
+ }, {
75
+ maxQueueUtilization: this.maxQueueUtilization,
76
+ maxTotalDropped: this.maxTotalDropped,
77
+ maxUnhealthyExporters: this.maxUnhealthyExporters
78
+ });
79
+ }
80
+ evaluate() {
81
+ const now = Date.now();
82
+ const { failures, queueStats, unhealthyExporterCount } = this.collectFailures();
83
+ let action = 'hold';
84
+ if (failures.length > 0) {
85
+ this.consecutiveHealthy = 0;
86
+ this.consecutiveFailures += 1;
87
+ if ('rolled_back' !== this.state && this.consecutiveFailures >= this.rollbackConsecutiveFailures) {
88
+ this.state = 'rolled_back';
89
+ action = 'rollback';
90
+ }
91
+ } else {
92
+ this.consecutiveFailures = 0;
93
+ this.consecutiveHealthy += 1;
94
+ if ('canary' === this.state && this.consecutiveHealthy >= this.minConsecutiveHealthyEvaluations) {
95
+ this.state = 'promoted';
96
+ action = 'promote';
97
+ }
98
+ }
99
+ const decision = {
100
+ timestamp: now,
101
+ action,
102
+ state: this.state,
103
+ consecutiveHealthy: this.consecutiveHealthy,
104
+ consecutiveFailures: this.consecutiveFailures,
105
+ failures,
106
+ queueStats,
107
+ unhealthyExporterCount,
108
+ contractGates: Array.from(this.contractGates.values()).map((item)=>({
109
+ ...item
110
+ }))
111
+ };
112
+ try {
113
+ this.onEvaluate?.(decision);
114
+ } catch (_error) {}
115
+ if ('promote' === action) try {
116
+ this.onPromote?.(decision);
117
+ } catch (_error) {}
118
+ if ('rollback' === action) try {
119
+ this.onRollback?.(decision);
120
+ } catch (_error) {}
121
+ return decision;
122
+ }
123
+ getStatusSnapshot() {
124
+ const now = Date.now();
125
+ const { failures, queueStats, unhealthyExporterCount } = this.collectFailures();
126
+ return {
127
+ timestamp: now,
128
+ state: this.state,
129
+ consecutiveHealthy: this.consecutiveHealthy,
130
+ consecutiveFailures: this.consecutiveFailures,
131
+ queueStats,
132
+ unhealthyExporterCount,
133
+ requiredContractGates: [
134
+ ...this.requiredContractGates
135
+ ],
136
+ contractGates: Array.from(this.contractGates.values()).map((item)=>({
137
+ ...item
138
+ })),
139
+ failurePreview: failures
140
+ };
141
+ }
142
+ start() {
143
+ if (this.evaluationTimer) return;
144
+ this.evaluationTimer = setInterval(()=>{
145
+ this.evaluate();
146
+ }, this.evaluationIntervalMs);
147
+ if ('function' == typeof this.evaluationTimer.unref) this.evaluationTimer.unref();
148
+ }
149
+ stop() {
150
+ if (this.evaluationTimer) {
151
+ clearInterval(this.evaluationTimer);
152
+ this.evaluationTimer = void 0;
153
+ }
154
+ }
155
+ constructor(options){
156
+ this.requiredContractGates = [];
157
+ this.contractGates = new Map();
158
+ this.state = 'canary';
159
+ this.consecutiveHealthy = 0;
160
+ this.consecutiveFailures = 0;
161
+ this.registry = options.registry;
162
+ this.evaluationIntervalMs = Math.max(250, options.evaluationIntervalMs ?? 15000);
163
+ this.minConsecutiveHealthyEvaluations = Math.max(1, options.minConsecutiveHealthyEvaluations ?? 3);
164
+ this.rollbackConsecutiveFailures = Math.max(1, options.rollbackConsecutiveFailures ?? 2);
165
+ this.maxQueueUtilization = (0, external_envelope_js_namespaceObject.clamp)(options.maxQueueUtilization ?? 0.8, 0, 1);
166
+ this.maxTotalDropped = Math.max(0, options.maxTotalDropped ?? 0);
167
+ this.maxUnhealthyExporters = Math.max(0, options.maxUnhealthyExporters ?? 0);
168
+ this.setRequiredContractGates(options.requiredContractGates || []);
169
+ this.onEvaluate = options.onEvaluate;
170
+ this.onPromote = options.onPromote;
171
+ this.onRollback = options.onRollback;
172
+ }
173
+ }
174
+ exports.TelemetryCanaryOrchestrator = __webpack_exports__.TelemetryCanaryOrchestrator;
175
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
176
+ "TelemetryCanaryOrchestrator"
177
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
178
+ Object.defineProperty(exports, '__esModule', {
179
+ value: true
180
+ });
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const evaluateCanaryHealth = (metrics, thresholds)=>{
31
+ const failures = [];
32
+ const { queueStats, unhealthyExporterCount } = metrics;
33
+ if (queueStats.utilization > thresholds.maxQueueUtilization) failures.push({
34
+ reason: 'queue_utilization',
35
+ threshold: thresholds.maxQueueUtilization,
36
+ value: queueStats.utilization
37
+ });
38
+ if (queueStats.totalDropped > thresholds.maxTotalDropped) failures.push({
39
+ reason: 'queue_dropped',
40
+ threshold: thresholds.maxTotalDropped,
41
+ value: queueStats.totalDropped
42
+ });
43
+ if (unhealthyExporterCount > thresholds.maxUnhealthyExporters) failures.push({
44
+ reason: 'unhealthy_exporter',
45
+ threshold: thresholds.maxUnhealthyExporters,
46
+ value: unhealthyExporterCount
47
+ });
48
+ for (const gateName of metrics.requiredContractGates){
49
+ const gate = metrics.contractGates.get(gateName);
50
+ if (!gate) {
51
+ failures.push({
52
+ reason: 'contract_gate_missing',
53
+ gate: gateName,
54
+ message: `Contract gate "${gateName}" is missing`
55
+ });
56
+ continue;
57
+ }
58
+ if (!gate.passed) failures.push({
59
+ reason: 'contract_gate_failed',
60
+ gate: gateName,
61
+ message: gate.reason || `Contract gate "${gateName}" is not passing`
62
+ });
63
+ }
64
+ return {
65
+ failures,
66
+ queueStats,
67
+ unhealthyExporterCount
68
+ };
69
+ };
70
+ __webpack_require__.d(__webpack_exports__, {}, {
71
+ evaluateCanaryHealth: evaluateCanaryHealth
72
+ });
73
+ exports.evaluateCanaryHealth = __webpack_exports__.evaluateCanaryHealth;
74
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
75
+ "evaluateCanaryHealth"
76
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
77
+ Object.defineProperty(exports, '__esModule', {
78
+ value: true
79
+ });