@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
@@ -0,0 +1,157 @@
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 DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = '/_modern/contract-gates/runtime-fallback';
31
+ const DEFAULT_RUNTIME_STATUS_ENDPOINT = '/_modern/runtime/status';
32
+ const DEFAULT_RUNTIME_FALLBACK_GATE_NAME = 'runtime-mf-fallback-health';
33
+ const DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS = 300000;
34
+ const DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES = 16384;
35
+ const DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER = 'x-modernjs-runtime-signal-token';
36
+ const DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW = 30;
37
+ const DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS = 60000;
38
+ const DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS = 10000;
39
+ function createRuntimeSignalError(message, code) {
40
+ const error = new Error(message);
41
+ error.code = code;
42
+ return error;
43
+ }
44
+ function getRuntimeSignalErrorStatusCode(signalError) {
45
+ if ('PAYLOAD_TOO_LARGE' === signalError.code) return 413;
46
+ if ('INVALID_PAYLOAD' === signalError.code) return 400;
47
+ if ('UNAUTHORIZED' === signalError.code) return 401;
48
+ if ('RATE_LIMITED' === signalError.code) return 429;
49
+ if ('UNTRUSTED_SOURCE' === signalError.code) return 403;
50
+ return 500;
51
+ }
52
+ function normalizeRuntimeSignalOrigin(value) {
53
+ if ('string' != typeof value || 0 === value.trim().length) return;
54
+ try {
55
+ return new URL(value).origin;
56
+ } catch (_error) {
57
+ return;
58
+ }
59
+ }
60
+ function normalizeRuntimeSignalAppName(payload) {
61
+ if ('string' != typeof payload.appName) return 'unknown';
62
+ const normalized = payload.appName.trim();
63
+ return normalized.length > 0 ? normalized : 'unknown';
64
+ }
65
+ function normalizeRuntimeSignalRuntimeDigest(payload) {
66
+ if ('string' == typeof payload.runtimeDigest && payload.runtimeDigest.trim()) return payload.runtimeDigest.trim();
67
+ const metadata = payload.metadata;
68
+ if (metadata && 'object' == typeof metadata && !Array.isArray(metadata) && 'string' == typeof metadata.runtimeDigest) {
69
+ const digest = String(metadata.runtimeDigest).trim();
70
+ if (digest) return digest;
71
+ }
72
+ }
73
+ function getUtf8ByteLength(input) {
74
+ if ("u" > typeof Buffer) return Buffer.byteLength(input);
75
+ return new TextEncoder().encode(input).length;
76
+ }
77
+ async function parseRuntimeFallbackSignalPayload(c, maxBodyBytes) {
78
+ const contentLengthHeader = c.req.header('content-length');
79
+ if (contentLengthHeader) {
80
+ const contentLength = Number.parseInt(contentLengthHeader, 10);
81
+ if (Number.isFinite(contentLength) && contentLength > maxBodyBytes) throw createRuntimeSignalError('runtime fallback signal payload too large', 'PAYLOAD_TOO_LARGE');
82
+ }
83
+ const rawBody = await c.req.raw.text();
84
+ const payload = parseRuntimeFallbackSignalPayloadFromRawBody(rawBody, maxBodyBytes);
85
+ return {
86
+ rawBody,
87
+ payload
88
+ };
89
+ }
90
+ function parseRuntimeFallbackSignalPayloadFromRawBody(rawBody, maxBodyBytes) {
91
+ if (!rawBody || 0 === rawBody.trim().length) throw createRuntimeSignalError('runtime fallback signal body empty', 'INVALID_PAYLOAD');
92
+ if (getUtf8ByteLength(rawBody) > maxBodyBytes) throw createRuntimeSignalError('runtime fallback signal payload too large', 'PAYLOAD_TOO_LARGE');
93
+ let payload;
94
+ try {
95
+ payload = JSON.parse(rawBody);
96
+ } catch (_error) {
97
+ throw createRuntimeSignalError('runtime fallback signal body must be valid JSON', 'INVALID_PAYLOAD');
98
+ }
99
+ if (!payload || 'object' != typeof payload || Array.isArray(payload)) throw createRuntimeSignalError('runtime fallback signal body must be a JSON object', 'INVALID_PAYLOAD');
100
+ return payload;
101
+ }
102
+ __webpack_require__.d(__webpack_exports__, {
103
+ createRuntimeSignalError: ()=>createRuntimeSignalError,
104
+ getRuntimeSignalErrorStatusCode: ()=>getRuntimeSignalErrorStatusCode,
105
+ normalizeRuntimeSignalAppName: ()=>normalizeRuntimeSignalAppName,
106
+ normalizeRuntimeSignalOrigin: ()=>normalizeRuntimeSignalOrigin,
107
+ normalizeRuntimeSignalRuntimeDigest: ()=>normalizeRuntimeSignalRuntimeDigest,
108
+ parseRuntimeFallbackSignalPayload: ()=>parseRuntimeFallbackSignalPayload,
109
+ parseRuntimeFallbackSignalPayloadFromRawBody: ()=>parseRuntimeFallbackSignalPayloadFromRawBody
110
+ }, {
111
+ DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER: DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER,
112
+ DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS: DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS,
113
+ DEFAULT_RUNTIME_FALLBACK_GATE_NAME: DEFAULT_RUNTIME_FALLBACK_GATE_NAME,
114
+ DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES: DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES,
115
+ DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT: DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT,
116
+ DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS: DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS,
117
+ DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW: DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW,
118
+ DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS: DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS,
119
+ DEFAULT_RUNTIME_STATUS_ENDPOINT: DEFAULT_RUNTIME_STATUS_ENDPOINT
120
+ });
121
+ exports.DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER;
122
+ exports.DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS;
123
+ exports.DEFAULT_RUNTIME_FALLBACK_GATE_NAME = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_GATE_NAME;
124
+ exports.DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES;
125
+ exports.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT;
126
+ exports.DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS;
127
+ exports.DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW;
128
+ exports.DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS = __webpack_exports__.DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS;
129
+ exports.DEFAULT_RUNTIME_STATUS_ENDPOINT = __webpack_exports__.DEFAULT_RUNTIME_STATUS_ENDPOINT;
130
+ exports.createRuntimeSignalError = __webpack_exports__.createRuntimeSignalError;
131
+ exports.getRuntimeSignalErrorStatusCode = __webpack_exports__.getRuntimeSignalErrorStatusCode;
132
+ exports.normalizeRuntimeSignalAppName = __webpack_exports__.normalizeRuntimeSignalAppName;
133
+ exports.normalizeRuntimeSignalOrigin = __webpack_exports__.normalizeRuntimeSignalOrigin;
134
+ exports.normalizeRuntimeSignalRuntimeDigest = __webpack_exports__.normalizeRuntimeSignalRuntimeDigest;
135
+ exports.parseRuntimeFallbackSignalPayload = __webpack_exports__.parseRuntimeFallbackSignalPayload;
136
+ exports.parseRuntimeFallbackSignalPayloadFromRawBody = __webpack_exports__.parseRuntimeFallbackSignalPayloadFromRawBody;
137
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
138
+ "DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER",
139
+ "DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS",
140
+ "DEFAULT_RUNTIME_FALLBACK_GATE_NAME",
141
+ "DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES",
142
+ "DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT",
143
+ "DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS",
144
+ "DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW",
145
+ "DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS",
146
+ "DEFAULT_RUNTIME_STATUS_ENDPOINT",
147
+ "createRuntimeSignalError",
148
+ "getRuntimeSignalErrorStatusCode",
149
+ "normalizeRuntimeSignalAppName",
150
+ "normalizeRuntimeSignalOrigin",
151
+ "normalizeRuntimeSignalRuntimeDigest",
152
+ "parseRuntimeFallbackSignalPayload",
153
+ "parseRuntimeFallbackSignalPayloadFromRawBody"
154
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
155
+ Object.defineProperty(exports, '__esModule', {
156
+ value: true
157
+ });
@@ -0,0 +1,163 @@
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
+ enforceRuntimeFallbackSignalAuth: ()=>enforceRuntimeFallbackSignalAuth,
32
+ enforceRuntimeFallbackSignalAuthToken: ()=>enforceRuntimeFallbackSignalAuthToken,
33
+ enforceRuntimeFallbackSignalTrustPolicy: ()=>enforceRuntimeFallbackSignalTrustPolicy,
34
+ normalizeRequiredRuntimeFallbackSignalAuthConfig: ()=>normalizeRequiredRuntimeFallbackSignalAuthConfig,
35
+ normalizeRuntimeFallbackSignalAuthConfig: ()=>normalizeRuntimeFallbackSignalAuthConfig,
36
+ normalizeRuntimeFallbackTrustPolicy: ()=>normalizeRuntimeFallbackTrustPolicy,
37
+ resolveRuntimeFallbackSignalEndpoint: ()=>resolveRuntimeFallbackSignalEndpoint
38
+ });
39
+ const external_node_crypto_namespaceObject = require("node:crypto");
40
+ const external_model_js_namespaceObject = require("./model.js");
41
+ const external_store_js_namespaceObject = require("./store.js");
42
+ function resolveRuntimeFallbackSignalEndpoint(configuredEndpoint) {
43
+ if ('string' == typeof configuredEndpoint && configuredEndpoint.trim()) return configuredEndpoint.trim();
44
+ return external_model_js_namespaceObject.DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT;
45
+ }
46
+ function normalizeRuntimeFallbackSignalAuthConfig(configured) {
47
+ const headerName = 'string' == typeof configured?.headerName && configured.headerName.trim() ? configured.headerName.trim().toLowerCase() : external_model_js_namespaceObject.DEFAULT_RUNTIME_FALLBACK_AUTH_HEADER;
48
+ const expectedFromEnv = 'string' == typeof configured?.expectedValueEnv && configured.expectedValueEnv.trim().length > 0 ? process.env[configured.expectedValueEnv.trim()] : void 0;
49
+ const expectedFromConfig = 'string' == typeof configured?.expectedValue && configured.expectedValue.trim().length > 0 ? configured.expectedValue.trim() : void 0;
50
+ const expectedValue = expectedFromConfig || expectedFromEnv;
51
+ const enabled = configured?.enabled === true;
52
+ if (enabled && !expectedValue) throw new Error('[telemetry.canary.autopilot.runtimeFallbackSignal] auth.enabled true but no expected token configured');
53
+ return {
54
+ enabled,
55
+ headerName,
56
+ expectedValue
57
+ };
58
+ }
59
+ function normalizeRequiredRuntimeFallbackSignalAuthConfig(configured) {
60
+ if (configured?.enabled === false) throw new Error('[telemetry.canary.autopilot.runtimeFallbackSignal] auth.enabled cannot be false when runtimeFallbackSignal.enabled is true');
61
+ const authConfig = normalizeRuntimeFallbackSignalAuthConfig(configured);
62
+ if (!authConfig.expectedValue) throw new Error('[telemetry.canary.autopilot.runtimeFallbackSignal] auth.expectedValue or auth.expectedValueEnv is required when runtimeFallbackSignal.enabled is true');
63
+ return {
64
+ ...authConfig,
65
+ enabled: true
66
+ };
67
+ }
68
+ function safeTokenEquals(candidate, expected) {
69
+ const candidateDigest = (0, external_node_crypto_namespaceObject.createHash)('sha256').update(candidate).digest();
70
+ const expectedDigest = (0, external_node_crypto_namespaceObject.createHash)('sha256').update(expected).digest();
71
+ return (0, external_node_crypto_namespaceObject.timingSafeEqual)(candidateDigest, expectedDigest);
72
+ }
73
+ function enforceRuntimeFallbackSignalAuthToken(token, authConfig) {
74
+ if (!authConfig.enabled) return;
75
+ if (!token || !authConfig.expectedValue || !safeTokenEquals(token, authConfig.expectedValue)) throw (0, external_model_js_namespaceObject.createRuntimeSignalError)('runtime fallback signal auth failed', 'UNAUTHORIZED');
76
+ }
77
+ function enforceRuntimeFallbackSignalAuth(c, runtimeSignalConfig) {
78
+ enforceRuntimeFallbackSignalAuthToken(c.req.header(runtimeSignalConfig.auth.headerName), runtimeSignalConfig.auth);
79
+ }
80
+ const normalizeInteger = (value, fallback, minimum)=>{
81
+ const candidate = 'number' == typeof value && Number.isFinite(value) ? value : fallback;
82
+ return Math.max(minimum, Math.floor(candidate));
83
+ };
84
+ function normalizeRuntimeFallbackTrustPolicy(configured) {
85
+ const allowedApps = Array.isArray(configured?.allowedApps) ? configured.allowedApps.map((item)=>'string' == typeof item ? item.trim() : '').filter(Boolean) : [];
86
+ const allowedEntryOrigins = Array.isArray(configured?.allowedEntryOrigins) ? configured.allowedEntryOrigins.map((item)=>(0, external_model_js_namespaceObject.normalizeRuntimeSignalOrigin)(item)).filter((item)=>Boolean(item)) : [];
87
+ const expectedRuntimeDigests = {};
88
+ Object.entries(configured?.expectedRuntimeDigests || {}).forEach(([appName, digest])=>{
89
+ if ('string' == typeof appName && appName.trim().length > 0 && 'string' == typeof digest && digest.trim().length > 0) expectedRuntimeDigests[appName.trim()] = digest.trim();
90
+ });
91
+ return {
92
+ allowedApps,
93
+ allowedEntryOrigins,
94
+ expectedRuntimeDigests,
95
+ enforceRuntimeDigest: configured?.enforceRuntimeDigest === true,
96
+ maxSignalsPerWindow: normalizeInteger(configured?.maxSignalsPerWindow, external_model_js_namespaceObject.DEFAULT_RUNTIME_FALLBACK_TRUST_MAX_SIGNALS_PER_WINDOW, 1),
97
+ windowMs: normalizeInteger(configured?.windowMs, external_model_js_namespaceObject.DEFAULT_RUNTIME_FALLBACK_TRUST_WINDOW_MS, 1),
98
+ dedupeWindowMs: normalizeInteger(configured?.dedupeWindowMs, external_model_js_namespaceObject.DEFAULT_RUNTIME_FALLBACK_TRUST_DEDUPE_WINDOW_MS, 0)
99
+ };
100
+ }
101
+ function enforceRuntimeFallbackSignalTrustPolicy(payload, runtimeSignalContext, source = {}) {
102
+ const { trustPolicy, runtimeState } = runtimeSignalContext;
103
+ const now = Date.now();
104
+ (0, external_store_js_namespaceObject.cleanupRuntimeFallbackSignalRuntimeState)(now, runtimeState, trustPolicy);
105
+ const appName = (0, external_model_js_namespaceObject.normalizeRuntimeSignalAppName)(payload);
106
+ const entryOrigin = (0, external_model_js_namespaceObject.normalizeRuntimeSignalOrigin)(payload.entry);
107
+ const runtimeDigest = (0, external_model_js_namespaceObject.normalizeRuntimeSignalRuntimeDigest)(payload);
108
+ if (trustPolicy.allowedApps.length > 0 && !trustPolicy.allowedApps.includes(appName)) throw (0, external_model_js_namespaceObject.createRuntimeSignalError)(`runtime fallback signal app "${appName}" is not trusted`, 'UNTRUSTED_SOURCE');
109
+ if (trustPolicy.allowedEntryOrigins.length > 0) {
110
+ if (!entryOrigin || !trustPolicy.allowedEntryOrigins.includes(entryOrigin)) throw (0, external_model_js_namespaceObject.createRuntimeSignalError)(`runtime fallback signal entry origin "${entryOrigin || 'unknown'}" is not trusted`, 'UNTRUSTED_SOURCE');
111
+ }
112
+ const expectedDigest = trustPolicy.expectedRuntimeDigests[appName];
113
+ if (expectedDigest && runtimeDigest !== expectedDigest) throw (0, external_model_js_namespaceObject.createRuntimeSignalError)(`runtime fallback runtimeDigest mismatch for app "${appName}"`, 'UNTRUSTED_SOURCE');
114
+ if (trustPolicy.enforceRuntimeDigest && !runtimeDigest) throw (0, external_model_js_namespaceObject.createRuntimeSignalError)(`runtime fallback signal app "${appName}" missing runtimeDigest`, 'UNTRUSTED_SOURCE');
115
+ const dedupeFingerprint = JSON.stringify({
116
+ appName,
117
+ entryOrigin: entryOrigin || 'unknown',
118
+ reason: payload.reason || 'runtime_fallback',
119
+ phase: payload.phase || 'unknown',
120
+ runtimeDigest: runtimeDigest || 'unknown'
121
+ });
122
+ const dedupeWindowMs = trustPolicy.dedupeWindowMs;
123
+ if (dedupeWindowMs > 0) {
124
+ const lastSeenAt = runtimeState.dedupeByFingerprint.get(dedupeFingerprint);
125
+ runtimeState.dedupeByFingerprint.set(dedupeFingerprint, now);
126
+ if ('number' == typeof lastSeenAt && now - lastSeenAt <= dedupeWindowMs) return {
127
+ deduped: true
128
+ };
129
+ } else runtimeState.dedupeByFingerprint.set(dedupeFingerprint, now);
130
+ const remoteAddress = source.remoteAddress?.trim();
131
+ const sourceKey = remoteAddress || 'unknown-remote';
132
+ const rateState = runtimeState.rateLimitBySource.get(sourceKey);
133
+ if (!rateState || now - rateState.windowStartedAt > trustPolicy.windowMs) runtimeState.rateLimitBySource.set(sourceKey, {
134
+ count: 1,
135
+ windowStartedAt: now
136
+ });
137
+ else {
138
+ if (rateState.count >= trustPolicy.maxSignalsPerWindow) throw (0, external_model_js_namespaceObject.createRuntimeSignalError)(`runtime fallback signal rate-limited source "${sourceKey}"`, 'RATE_LIMITED');
139
+ rateState.count += 1;
140
+ }
141
+ return {
142
+ deduped: false
143
+ };
144
+ }
145
+ exports.enforceRuntimeFallbackSignalAuth = __webpack_exports__.enforceRuntimeFallbackSignalAuth;
146
+ exports.enforceRuntimeFallbackSignalAuthToken = __webpack_exports__.enforceRuntimeFallbackSignalAuthToken;
147
+ exports.enforceRuntimeFallbackSignalTrustPolicy = __webpack_exports__.enforceRuntimeFallbackSignalTrustPolicy;
148
+ exports.normalizeRequiredRuntimeFallbackSignalAuthConfig = __webpack_exports__.normalizeRequiredRuntimeFallbackSignalAuthConfig;
149
+ exports.normalizeRuntimeFallbackSignalAuthConfig = __webpack_exports__.normalizeRuntimeFallbackSignalAuthConfig;
150
+ exports.normalizeRuntimeFallbackTrustPolicy = __webpack_exports__.normalizeRuntimeFallbackTrustPolicy;
151
+ exports.resolveRuntimeFallbackSignalEndpoint = __webpack_exports__.resolveRuntimeFallbackSignalEndpoint;
152
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
153
+ "enforceRuntimeFallbackSignalAuth",
154
+ "enforceRuntimeFallbackSignalAuthToken",
155
+ "enforceRuntimeFallbackSignalTrustPolicy",
156
+ "normalizeRequiredRuntimeFallbackSignalAuthConfig",
157
+ "normalizeRuntimeFallbackSignalAuthConfig",
158
+ "normalizeRuntimeFallbackTrustPolicy",
159
+ "resolveRuntimeFallbackSignalEndpoint"
160
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
161
+ Object.defineProperty(exports, '__esModule', {
162
+ value: true
163
+ });
@@ -28,9 +28,24 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
+ cleanupRuntimeFallbackSignalRuntimeState: ()=>cleanupRuntimeFallbackSignalRuntimeState,
32
+ createRuntimeFallbackSignalRuntimeState: ()=>createRuntimeFallbackSignalRuntimeState,
31
33
  persistRuntimeFallbackContractGate: ()=>persistRuntimeFallbackContractGate
32
34
  });
33
35
  const index_js_namespaceObject = require("../contract-gate-snapshot-store/index.js");
36
+ function createRuntimeFallbackSignalRuntimeState() {
37
+ return {
38
+ rateLimitBySource: new Map(),
39
+ dedupeByFingerprint: new Map()
40
+ };
41
+ }
42
+ function cleanupRuntimeFallbackSignalRuntimeState(now, runtimeState, trustPolicy) {
43
+ const rateLimitWindowMs = Math.max(1, trustPolicy.windowMs);
44
+ for (const [sourceKey, rateState] of runtimeState.rateLimitBySource)if (now - rateState.windowStartedAt > rateLimitWindowMs) runtimeState.rateLimitBySource.delete(sourceKey);
45
+ const dedupeWindowMs = Math.max(0, trustPolicy.dedupeWindowMs);
46
+ if (0 === dedupeWindowMs) return void runtimeState.dedupeByFingerprint.clear();
47
+ for (const [fingerprint, lastSeenAt] of runtimeState.dedupeByFingerprint)if (now - lastSeenAt > dedupeWindowMs) runtimeState.dedupeByFingerprint.delete(fingerprint);
48
+ }
34
49
  async function persistRuntimeFallbackContractGate(payload, runtimeSignalConfig) {
35
50
  const now = Date.now();
36
51
  const gateSnapshotStore = await runtimeSignalConfig.gateSnapshotStore;
@@ -55,8 +70,12 @@ async function persistRuntimeFallbackContractGate(payload, runtimeSignalConfig)
55
70
  };
56
71
  await gateSnapshotStore.writeSnapshot(snapshot);
57
72
  }
73
+ exports.cleanupRuntimeFallbackSignalRuntimeState = __webpack_exports__.cleanupRuntimeFallbackSignalRuntimeState;
74
+ exports.createRuntimeFallbackSignalRuntimeState = __webpack_exports__.createRuntimeFallbackSignalRuntimeState;
58
75
  exports.persistRuntimeFallbackContractGate = __webpack_exports__.persistRuntimeFallbackContractGate;
59
76
  for(var __rspack_i in __webpack_exports__)if (-1 === [
77
+ "cleanupRuntimeFallbackSignalRuntimeState",
78
+ "createRuntimeFallbackSignalRuntimeState",
60
79
  "persistRuntimeFallbackContractGate"
61
80
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
62
81
  Object.defineProperty(exports, '__esModule', {
@@ -27,6 +27,68 @@ var __webpack_require__ = {};
27
27
  })();
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
+ function buildDroppedEnvelope(context, droppedCount) {
31
+ return {
32
+ timestamp: Date.now(),
33
+ service: context.service,
34
+ module: context.module,
35
+ environment: context.environment,
36
+ signalType: 'metric',
37
+ name: 'telemetry.queue.dropped',
38
+ value: droppedCount,
39
+ unit: 'count',
40
+ tags: {
41
+ reason: 'queue_backpressure'
42
+ }
43
+ };
44
+ }
45
+ function buildQueueDepthEnvelope(context, queueDepth) {
46
+ return {
47
+ timestamp: Date.now(),
48
+ service: context.service,
49
+ module: context.module,
50
+ environment: context.environment,
51
+ signalType: 'metric',
52
+ name: 'telemetry.queue.depth',
53
+ value: queueDepth,
54
+ unit: 'count',
55
+ tags: {
56
+ capacity: String(context.maxQueueSize)
57
+ }
58
+ };
59
+ }
60
+ function buildQueueUtilizationEnvelope(context, queueDepth) {
61
+ return {
62
+ timestamp: Date.now(),
63
+ service: context.service,
64
+ module: context.module,
65
+ environment: context.environment,
66
+ signalType: 'metric',
67
+ name: 'telemetry.queue.utilization',
68
+ value: queueDepth / context.maxQueueSize,
69
+ unit: 'ratio',
70
+ tags: {
71
+ capacity: String(context.maxQueueSize)
72
+ }
73
+ };
74
+ }
75
+ function buildStartupProbeEnvelope(context) {
76
+ return {
77
+ timestamp: Date.now(),
78
+ service: context.service,
79
+ module: context.module,
80
+ environment: context.environment,
81
+ signalType: 'log',
82
+ name: 'telemetry.exporter.startup_probe',
83
+ level: 'info',
84
+ tags: {
85
+ phase: 'startup'
86
+ },
87
+ attributes: {
88
+ source: 'TelemetryRegistry'
89
+ }
90
+ };
91
+ }
30
92
  function clamp(value, min, max) {
31
93
  if (Number.isNaN(value)) return max;
32
94
  return Math.max(min, Math.min(max, value));
@@ -129,16 +191,28 @@ function toTelemetryEnvelope(event, input) {
129
191
  };
130
192
  }
131
193
  __webpack_require__.d(__webpack_exports__, {
194
+ buildDroppedEnvelope: ()=>buildDroppedEnvelope,
195
+ buildQueueDepthEnvelope: ()=>buildQueueDepthEnvelope,
196
+ buildQueueUtilizationEnvelope: ()=>buildQueueUtilizationEnvelope,
197
+ buildStartupProbeEnvelope: ()=>buildStartupProbeEnvelope,
132
198
  clamp: ()=>clamp,
133
199
  isRecord: ()=>isRecord,
134
200
  redactObject: ()=>redactObject,
135
201
  toTelemetryEnvelope: ()=>toTelemetryEnvelope
136
202
  });
203
+ exports.buildDroppedEnvelope = __webpack_exports__.buildDroppedEnvelope;
204
+ exports.buildQueueDepthEnvelope = __webpack_exports__.buildQueueDepthEnvelope;
205
+ exports.buildQueueUtilizationEnvelope = __webpack_exports__.buildQueueUtilizationEnvelope;
206
+ exports.buildStartupProbeEnvelope = __webpack_exports__.buildStartupProbeEnvelope;
137
207
  exports.clamp = __webpack_exports__.clamp;
138
208
  exports.isRecord = __webpack_exports__.isRecord;
139
209
  exports.redactObject = __webpack_exports__.redactObject;
140
210
  exports.toTelemetryEnvelope = __webpack_exports__.toTelemetryEnvelope;
141
211
  for(var __rspack_i in __webpack_exports__)if (-1 === [
212
+ "buildDroppedEnvelope",
213
+ "buildQueueDepthEnvelope",
214
+ "buildQueueUtilizationEnvelope",
215
+ "buildStartupProbeEnvelope",
142
216
  "clamp",
143
217
  "isRecord",
144
218
  "redactObject",
@@ -118,10 +118,7 @@ class TelemetryRegistry {
118
118
  }
119
119
  enqueueMetric(input) {
120
120
  this.enqueue({
121
- timestamp: Date.now(),
122
- service: this.service,
123
- module: this.module,
124
- environment: this.environment,
121
+ ...this.baseEnvelope(),
125
122
  signalType: 'metric',
126
123
  name: input.name,
127
124
  value: input.value,
@@ -135,10 +132,7 @@ class TelemetryRegistry {
135
132
  }
136
133
  enqueueLog(input) {
137
134
  this.enqueue({
138
- timestamp: Date.now(),
139
- service: this.service,
140
- module: this.module,
141
- environment: this.environment,
135
+ ...this.baseEnvelope(),
142
136
  signalType: 'log',
143
137
  name: input.name,
144
138
  level: input.level,
@@ -152,10 +146,7 @@ class TelemetryRegistry {
152
146
  }
153
147
  enqueueTrace(input) {
154
148
  this.enqueue({
155
- timestamp: Date.now(),
156
- service: this.service,
157
- module: this.module,
158
- environment: this.environment,
149
+ ...this.baseEnvelope(),
159
150
  signalType: 'trace',
160
151
  name: input.name,
161
152
  traceId: input.traceId,
@@ -165,49 +156,12 @@ class TelemetryRegistry {
165
156
  attributes: input.attributes
166
157
  });
167
158
  }
168
- buildDroppedEnvelope(droppedCount) {
159
+ baseEnvelope() {
169
160
  return {
170
161
  timestamp: Date.now(),
171
162
  service: this.service,
172
163
  module: this.module,
173
- environment: this.environment,
174
- signalType: 'metric',
175
- name: 'telemetry.queue.dropped',
176
- value: droppedCount,
177
- unit: 'count',
178
- tags: {
179
- reason: 'queue_backpressure'
180
- }
181
- };
182
- }
183
- buildQueueDepthEnvelope(queueDepth) {
184
- return {
185
- timestamp: Date.now(),
186
- service: this.service,
187
- module: this.module,
188
- environment: this.environment,
189
- signalType: 'metric',
190
- name: 'telemetry.queue.depth',
191
- value: queueDepth,
192
- unit: 'count',
193
- tags: {
194
- capacity: String(this.maxQueueSize)
195
- }
196
- };
197
- }
198
- buildQueueUtilizationEnvelope(queueDepth) {
199
- return {
200
- timestamp: Date.now(),
201
- service: this.service,
202
- module: this.module,
203
- environment: this.environment,
204
- signalType: 'metric',
205
- name: 'telemetry.queue.utilization',
206
- value: queueDepth / this.maxQueueSize,
207
- unit: 'ratio',
208
- tags: {
209
- capacity: String(this.maxQueueSize)
210
- }
164
+ environment: this.environment
211
165
  };
212
166
  }
213
167
  async emitBatch(batch) {
@@ -224,27 +178,15 @@ class TelemetryRegistry {
224
178
  this.markExporterHealthy(exporterName);
225
179
  }
226
180
  }
227
- buildStartupProbeEnvelope() {
228
- return {
229
- timestamp: Date.now(),
230
- service: this.service,
231
- module: this.module,
232
- environment: this.environment,
233
- signalType: 'log',
234
- name: 'telemetry.exporter.startup_probe',
235
- level: 'info',
236
- tags: {
237
- phase: 'startup'
238
- },
239
- attributes: {
240
- source: 'TelemetryRegistry'
241
- }
242
- };
243
- }
244
181
  async startupHealthCheck(options) {
245
182
  if (0 === this.exporters.length) return;
246
183
  const probeBatch = [
247
- this.buildStartupProbeEnvelope()
184
+ (0, external_envelope_js_namespaceObject.buildStartupProbeEnvelope)({
185
+ service: this.service,
186
+ module: this.module,
187
+ environment: this.environment,
188
+ maxQueueSize: this.maxQueueSize
189
+ })
248
190
  ];
249
191
  const failedExporters = [];
250
192
  await Promise.all(this.exporters.map(async (exporter)=>{
@@ -277,14 +219,20 @@ class TelemetryRegistry {
277
219
  }
278
220
  async flushInternal() {
279
221
  const queueDepthBeforeFlush = this.queue.length;
222
+ const envelopeContext = {
223
+ service: this.service,
224
+ module: this.module,
225
+ environment: this.environment,
226
+ maxQueueSize: this.maxQueueSize
227
+ };
280
228
  if (queueDepthBeforeFlush > 0) {
281
- this.queue.unshift(this.buildQueueUtilizationEnvelope(queueDepthBeforeFlush));
282
- this.queue.unshift(this.buildQueueDepthEnvelope(queueDepthBeforeFlush));
229
+ this.queue.unshift((0, external_envelope_js_namespaceObject.buildQueueUtilizationEnvelope)(envelopeContext, queueDepthBeforeFlush));
230
+ this.queue.unshift((0, external_envelope_js_namespaceObject.buildQueueDepthEnvelope)(envelopeContext, queueDepthBeforeFlush));
283
231
  }
284
232
  if (this.droppedCount > 0) {
285
233
  const droppedCount = this.droppedCount;
286
234
  this.droppedCount = 0;
287
- this.queue.unshift(this.buildDroppedEnvelope(droppedCount));
235
+ this.queue.unshift((0, external_envelope_js_namespaceObject.buildDroppedEnvelope)(envelopeContext, droppedCount));
288
236
  }
289
237
  if (0 === this.queue.length) return;
290
238
  if (0 === this.exporters.length) {