@bleedingdev/modern-js-server-core 3.2.0-ultramodern.98 → 3.4.0-ultramodern.0
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.
- package/dist/cjs/adapters/node/helper/index.js +9 -5
- package/dist/cjs/adapters/node/helper/loadCache.js +9 -5
- package/dist/cjs/adapters/node/helper/loadConfig.js +9 -5
- package/dist/cjs/adapters/node/helper/loadEnv.js +9 -5
- package/dist/cjs/adapters/node/helper/loadPlugin.js +9 -5
- package/dist/cjs/adapters/node/helper/utils.js +12 -8
- package/dist/cjs/adapters/node/hono.js +9 -5
- package/dist/cjs/adapters/node/index.js +9 -5
- package/dist/cjs/adapters/node/node.js +9 -5
- package/dist/cjs/adapters/node/plugins/index.js +9 -5
- package/dist/cjs/adapters/node/plugins/nodeServer.js +12 -8
- package/dist/cjs/adapters/node/plugins/resource.js +10 -11
- package/dist/cjs/adapters/node/plugins/static.js +20 -190
- package/dist/cjs/adapters/node/plugins/staticModuleFederation.js +165 -0
- package/dist/cjs/adapters/node/plugins/staticPrecompressed.js +135 -0
- package/dist/cjs/constants.js +18 -13
- package/dist/cjs/context.js +9 -5
- package/dist/cjs/helper.js +12 -8
- package/dist/cjs/hono.js +9 -5
- package/dist/cjs/index.js +60 -32
- package/dist/cjs/plugins/compat/hooks.js +14 -10
- package/dist/cjs/plugins/compat/index.js +9 -5
- package/dist/cjs/plugins/default.js +9 -7
- package/dist/cjs/plugins/favicon.js +12 -8
- package/dist/cjs/plugins/index.js +11 -88
- package/dist/cjs/plugins/log.js +9 -5
- package/dist/cjs/plugins/middlewares.js +12 -8
- package/dist/cjs/plugins/monitors.js +9 -5
- package/dist/cjs/plugins/processedBy.js +12 -8
- package/dist/cjs/plugins/render/csrRscRender.js +9 -5
- package/dist/cjs/plugins/render/dataHandler.js +9 -5
- package/dist/cjs/plugins/render/index.js +12 -8
- package/dist/cjs/plugins/render/inject.js +12 -7
- package/dist/cjs/plugins/render/render.js +14 -6
- package/dist/cjs/plugins/render/renderRscHandler.js +9 -5
- package/dist/cjs/plugins/render/serverActionHandler.js +9 -5
- package/dist/cjs/plugins/render/ssrCache.js +9 -5
- package/dist/cjs/plugins/render/ssrRender.js +9 -5
- package/dist/cjs/plugins/render/utils.js +12 -8
- package/dist/cjs/plugins/route.js +9 -5
- package/dist/cjs/serverBase.js +9 -5
- package/dist/cjs/types/config/bffRuntime.js +18 -0
- package/dist/cjs/types/config/index.js +9 -5
- package/dist/cjs/types/config/serverTelemetry.js +18 -0
- package/dist/cjs/types/index.js +9 -5
- package/dist/cjs/types/plugins/index.js +9 -5
- package/dist/cjs/utils/entry.js +13 -9
- package/dist/cjs/utils/env.js +13 -9
- package/dist/cjs/utils/error.js +71 -5
- package/dist/cjs/utils/index.js +9 -5
- package/dist/cjs/utils/middlewareCollector.js +13 -9
- package/dist/cjs/utils/publicDir.js +9 -5
- package/dist/cjs/utils/request.js +16 -12
- package/dist/cjs/utils/serverConfig.js +9 -5
- package/dist/cjs/utils/storage.js +9 -5
- package/dist/cjs/utils/transformStream.js +13 -9
- package/dist/cjs/utils/warmup.js +12 -8
- package/dist/esm/adapters/node/plugins/resource.mjs +1 -6
- package/dist/esm/adapters/node/plugins/static.mjs +7 -181
- package/dist/esm/adapters/node/plugins/staticModuleFederation.mjs +96 -0
- package/dist/esm/adapters/node/plugins/staticPrecompressed.mjs +91 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/plugins/default.mjs +0 -2
- package/dist/esm/plugins/index.mjs +0 -3
- package/dist/esm/plugins/render/inject.mjs +3 -2
- package/dist/esm/plugins/render/render.mjs +7 -3
- package/dist/esm/types/config/bffRuntime.mjs +0 -0
- package/dist/esm/types/config/serverTelemetry.mjs +0 -0
- package/dist/esm/utils/error.mjs +54 -1
- package/dist/esm-node/adapters/node/plugins/resource.mjs +1 -6
- package/dist/esm-node/adapters/node/plugins/static.mjs +7 -181
- package/dist/esm-node/adapters/node/plugins/staticModuleFederation.mjs +97 -0
- package/dist/esm-node/adapters/node/plugins/staticPrecompressed.mjs +92 -0
- package/dist/esm-node/index.mjs +1 -1
- package/dist/esm-node/plugins/default.mjs +0 -2
- package/dist/esm-node/plugins/index.mjs +0 -3
- package/dist/esm-node/plugins/render/inject.mjs +3 -2
- package/dist/esm-node/plugins/render/render.mjs +5 -1
- package/dist/esm-node/types/config/bffRuntime.mjs +1 -0
- package/dist/esm-node/types/config/serverTelemetry.mjs +1 -0
- package/dist/esm-node/utils/error.mjs +54 -1
- package/dist/types/adapters/node/plugins/staticModuleFederation.d.ts +13 -0
- package/dist/types/adapters/node/plugins/staticPrecompressed.d.ts +13 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/plugins/index.d.ts +0 -3
- package/dist/types/types/config/bff.d.ts +2 -97
- package/dist/types/types/config/bffRuntime.d.ts +105 -0
- package/dist/types/types/config/server.d.ts +3 -337
- package/dist/types/types/config/serverTelemetry.d.ts +319 -0
- package/dist/types/types/plugins/base.d.ts +7 -2
- package/dist/types/types/plugins/index.d.ts +1 -1
- package/dist/types/utils/error.d.ts +16 -0
- package/package.json +11 -11
- package/dist/cjs/adapters/node/plugins/moduleFederationCss.js +0 -172
- package/dist/cjs/plugins/contractGateAutopilot.js +0 -158
- package/dist/cjs/plugins/contractGateSnapshotStore.js +0 -239
- package/dist/cjs/plugins/mfCache.js +0 -78
- package/dist/cjs/plugins/telemetry.js +0 -1283
- package/dist/esm/adapters/node/plugins/moduleFederationCss.mjs +0 -125
- package/dist/esm/plugins/contractGateAutopilot.mjs +0 -124
- package/dist/esm/plugins/contractGateSnapshotStore.mjs +0 -180
- package/dist/esm/plugins/mfCache.mjs +0 -35
- package/dist/esm/plugins/telemetry.mjs +0 -1195
- package/dist/esm-node/adapters/node/plugins/moduleFederationCss.mjs +0 -126
- package/dist/esm-node/plugins/contractGateAutopilot.mjs +0 -125
- package/dist/esm-node/plugins/contractGateSnapshotStore.mjs +0 -182
- package/dist/esm-node/plugins/mfCache.mjs +0 -36
- package/dist/esm-node/plugins/telemetry.mjs +0 -1196
- package/dist/types/adapters/node/plugins/moduleFederationCss.d.ts +0 -33
- package/dist/types/plugins/contractGateAutopilot.d.ts +0 -35
- package/dist/types/plugins/contractGateSnapshotStore.d.ts +0 -57
- package/dist/types/plugins/mfCache.d.ts +0 -12
- package/dist/types/plugins/telemetry.d.ts +0 -309
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: definition[key]
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
})();
|
|
11
|
-
(()=>{
|
|
12
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
-
})();
|
|
14
|
-
(()=>{
|
|
15
|
-
__webpack_require__.r = (exports1)=>{
|
|
16
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
-
value: 'Module'
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
-
value: true
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
var __webpack_exports__ = {};
|
|
25
|
-
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
ContractGateAutopilot: ()=>ContractGateAutopilot
|
|
28
|
-
});
|
|
29
|
-
const external_contractGateSnapshotStore_js_namespaceObject = require("./contractGateSnapshotStore.js");
|
|
30
|
-
const DEFAULT_POLL_INTERVAL_MS = 15000;
|
|
31
|
-
const DEFAULT_GATE_STALE_AFTER_MS = 600000;
|
|
32
|
-
class ContractGateAutopilot {
|
|
33
|
-
async start() {
|
|
34
|
-
await this.syncOnce();
|
|
35
|
-
if (this.poller) return;
|
|
36
|
-
this.poller = setInterval(()=>{
|
|
37
|
-
this.syncOnce();
|
|
38
|
-
}, this.pollIntervalMs);
|
|
39
|
-
if ('function' == typeof this.poller.unref) this.poller.unref();
|
|
40
|
-
}
|
|
41
|
-
stop() {
|
|
42
|
-
if (this.poller) {
|
|
43
|
-
clearInterval(this.poller);
|
|
44
|
-
this.poller = void 0;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
async syncOnce() {
|
|
48
|
-
const snapshot = await this.loadSnapshot();
|
|
49
|
-
if (!snapshot) return 0;
|
|
50
|
-
const gates = this.normalizeSnapshot(snapshot);
|
|
51
|
-
let updatedCount = 0;
|
|
52
|
-
for (const gate of gates){
|
|
53
|
-
this.orchestrator.addRequiredContractGate(gate.name);
|
|
54
|
-
const fingerprint = `${gate.passed ? '1' : '0'}:${gate.reason || ''}`;
|
|
55
|
-
if (this.appliedGateFingerprints.get(gate.name) !== fingerprint) {
|
|
56
|
-
this.orchestrator.setContractGate(gate.name, gate.passed, gate.reason);
|
|
57
|
-
this.appliedGateFingerprints.set(gate.name, fingerprint);
|
|
58
|
-
updatedCount += 1;
|
|
59
|
-
this.logger?.info?.(`[telemetry.canary.autopilot] gate=${gate.name} passed=${String(gate.passed)} reason=${gate.reason || 'none'}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return updatedCount;
|
|
63
|
-
}
|
|
64
|
-
async loadSnapshot() {
|
|
65
|
-
try {
|
|
66
|
-
const snapshot = await this.gateSnapshotStore.readSnapshot();
|
|
67
|
-
if (!snapshot) return;
|
|
68
|
-
const fingerprint = JSON.stringify(snapshot);
|
|
69
|
-
if (fingerprint === this.lastSnapshotFingerprint) return;
|
|
70
|
-
this.lastSnapshotFingerprint = fingerprint;
|
|
71
|
-
return snapshot;
|
|
72
|
-
} catch (error) {
|
|
73
|
-
const source = this.gateSnapshotPath || this.gateSnapshotStore.name || 'stateStore';
|
|
74
|
-
this.logger?.warn?.(`[telemetry.canary.autopilot] failed to load gate snapshot ${source}: ${error instanceof Error ? error.message : String(error)}`);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
normalizeSnapshot(snapshot) {
|
|
79
|
-
const now = Date.now();
|
|
80
|
-
const output = [];
|
|
81
|
-
const gates = snapshot.gates;
|
|
82
|
-
if (!gates || 'object' != typeof gates) return output;
|
|
83
|
-
for (const [name, value] of Object.entries(gates)){
|
|
84
|
-
const normalizedName = name.trim();
|
|
85
|
-
if (!normalizedName) continue;
|
|
86
|
-
const gate = this.normalizeGateValue(value, snapshot.updatedAt, now);
|
|
87
|
-
if (!gate) continue;
|
|
88
|
-
if ('number' == typeof gate.expiresAt && Number.isFinite(gate.expiresAt) && gate.expiresAt > 0 && now >= gate.expiresAt) {
|
|
89
|
-
output.push({
|
|
90
|
-
name: normalizedName,
|
|
91
|
-
passed: true,
|
|
92
|
-
reason: void 0,
|
|
93
|
-
updatedAt: gate.updatedAt,
|
|
94
|
-
expiresAt: gate.expiresAt
|
|
95
|
-
});
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
const isStale = this.gateStaleAfterMs > 0 && now - gate.updatedAt > this.gateStaleAfterMs;
|
|
99
|
-
if (isStale) {
|
|
100
|
-
output.push({
|
|
101
|
-
name: normalizedName,
|
|
102
|
-
passed: false,
|
|
103
|
-
reason: gate.reason || 'Gate snapshot is stale',
|
|
104
|
-
updatedAt: gate.updatedAt
|
|
105
|
-
});
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
output.push({
|
|
109
|
-
name: normalizedName,
|
|
110
|
-
passed: gate.passed,
|
|
111
|
-
reason: gate.reason,
|
|
112
|
-
updatedAt: gate.updatedAt
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return output;
|
|
116
|
-
}
|
|
117
|
-
normalizeGateValue(value, snapshotUpdatedAt, now) {
|
|
118
|
-
if ('boolean' == typeof value) return {
|
|
119
|
-
passed: value,
|
|
120
|
-
updatedAt: this.normalizeUpdatedAt(snapshotUpdatedAt, now)
|
|
121
|
-
};
|
|
122
|
-
if (!value || 'object' != typeof value) return;
|
|
123
|
-
const hasPassed = 'boolean' == typeof value.passed;
|
|
124
|
-
const passed = true === value.passed;
|
|
125
|
-
let reason = 'string' == typeof value.reason && value.reason.trim().length > 0 ? value.reason : void 0;
|
|
126
|
-
if (!hasPassed) reason = reason || 'Gate snapshot record is missing "passed" boolean';
|
|
127
|
-
return {
|
|
128
|
-
passed,
|
|
129
|
-
reason,
|
|
130
|
-
updatedAt: this.normalizeUpdatedAt(value.updatedAt ?? snapshotUpdatedAt, now),
|
|
131
|
-
expiresAt: this.normalizeExpiresAt(value.expiresAt)
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
normalizeUpdatedAt(value, fallback) {
|
|
135
|
-
if ('number' == typeof value && Number.isFinite(value) && value > 0) return value;
|
|
136
|
-
return fallback;
|
|
137
|
-
}
|
|
138
|
-
normalizeExpiresAt(value) {
|
|
139
|
-
if ('number' == typeof value && Number.isFinite(value) && value > 0) return value;
|
|
140
|
-
}
|
|
141
|
-
constructor(options){
|
|
142
|
-
this.appliedGateFingerprints = new Map();
|
|
143
|
-
this.orchestrator = options.orchestrator;
|
|
144
|
-
if (!options.gateSnapshotStore && !options.gateSnapshotPath) throw new Error('ContractGateAutopilot requires gateSnapshotPath or gateSnapshotStore');
|
|
145
|
-
this.gateSnapshotPath = options.gateSnapshotPath;
|
|
146
|
-
this.gateSnapshotStore = options.gateSnapshotStore || (0, external_contractGateSnapshotStore_js_namespaceObject.createFileContractGateSnapshotStore)(options.gateSnapshotPath);
|
|
147
|
-
this.pollIntervalMs = Math.max(250, options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS);
|
|
148
|
-
this.gateStaleAfterMs = Math.max(0, options.gateStaleAfterMs ?? DEFAULT_GATE_STALE_AFTER_MS);
|
|
149
|
-
this.logger = options.logger;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
exports.ContractGateAutopilot = __webpack_exports__.ContractGateAutopilot;
|
|
153
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
154
|
-
"ContractGateAutopilot"
|
|
155
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
156
|
-
Object.defineProperty(exports, '__esModule', {
|
|
157
|
-
value: true
|
|
158
|
-
});
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
|
-
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: definition[key]
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
})();
|
|
20
|
-
(()=>{
|
|
21
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
-
})();
|
|
23
|
-
(()=>{
|
|
24
|
-
__webpack_require__.r = (exports1)=>{
|
|
25
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
-
value: 'Module'
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
-
value: true
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
})();
|
|
33
|
-
var __webpack_exports__ = {};
|
|
34
|
-
__webpack_require__.r(__webpack_exports__);
|
|
35
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION: ()=>CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION,
|
|
37
|
-
DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH: ()=>DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH,
|
|
38
|
-
createFileContractGateSnapshotStore: ()=>createFileContractGateSnapshotStore,
|
|
39
|
-
createHttpContractGateSnapshotStore: ()=>createHttpContractGateSnapshotStore,
|
|
40
|
-
resolveContractGateSnapshotPath: ()=>resolveContractGateSnapshotPath,
|
|
41
|
-
resolveContractGateSnapshotStore: ()=>resolveContractGateSnapshotStore
|
|
42
|
-
});
|
|
43
|
-
const utils_namespaceObject = require("@modern-js/utils");
|
|
44
|
-
const external_fs_namespaceObject = require("fs");
|
|
45
|
-
const external_path_namespaceObject = require("path");
|
|
46
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
47
|
-
const CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION = 1;
|
|
48
|
-
const DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH = '.modern/contract-gates.json';
|
|
49
|
-
const DEFAULT_HTTP_STORE_TIMEOUT_MS = 5000;
|
|
50
|
-
const BUILTIN_HTTP_STATE_STORE_MODULES = new Set([
|
|
51
|
-
'http',
|
|
52
|
-
'@modern-js/server-core/http',
|
|
53
|
-
'@modern-js/server-core/contract-gate-http-store'
|
|
54
|
-
]);
|
|
55
|
-
const isRecord = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
|
|
56
|
-
const normalizeSnapshot = (snapshot)=>{
|
|
57
|
-
if (!isRecord(snapshot)) return;
|
|
58
|
-
const schemaVersion = 'number' == typeof snapshot.schemaVersion ? snapshot.schemaVersion : CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION;
|
|
59
|
-
const updatedAt = 'number' == typeof snapshot.updatedAt ? snapshot.updatedAt : Date.now();
|
|
60
|
-
const gates = isRecord(snapshot.gates) ? snapshot.gates : {};
|
|
61
|
-
return {
|
|
62
|
-
schemaVersion,
|
|
63
|
-
updatedAt,
|
|
64
|
-
gates
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
const normalizeHttpStoreOptions = (options)=>{
|
|
68
|
-
const endpoint = 'string' == typeof options?.endpoint ? options.endpoint.trim() : '';
|
|
69
|
-
if (!endpoint) throw new Error('[telemetry.canary.autopilot] HTTP stateStore requires options.endpoint');
|
|
70
|
-
const readMethod = 'string' == typeof options?.readMethod && options.readMethod.trim() ? options.readMethod.trim().toUpperCase() : 'GET';
|
|
71
|
-
const writeMethod = 'string' == typeof options?.writeMethod && options.writeMethod.trim() ? options.writeMethod.trim().toUpperCase() : 'PUT';
|
|
72
|
-
const timeoutMsRaw = Number(options?.timeoutMs);
|
|
73
|
-
const timeoutMs = Number.isFinite(timeoutMsRaw) && timeoutMsRaw > 0 ? Math.floor(timeoutMsRaw) : DEFAULT_HTTP_STORE_TIMEOUT_MS;
|
|
74
|
-
const headersRaw = options?.headers;
|
|
75
|
-
const headers = {};
|
|
76
|
-
if (headersRaw && 'object' == typeof headersRaw && !Array.isArray(headersRaw)) Object.entries(headersRaw).forEach(([key, value])=>{
|
|
77
|
-
if ('string' == typeof key && key.trim().length > 0 && null != value) headers[key] = String(value);
|
|
78
|
-
});
|
|
79
|
-
return {
|
|
80
|
-
endpoint,
|
|
81
|
-
readMethod,
|
|
82
|
-
writeMethod,
|
|
83
|
-
headers,
|
|
84
|
-
timeoutMs
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
const withTimeoutAbort = (timeoutMs)=>{
|
|
88
|
-
const controller = new AbortController();
|
|
89
|
-
const timer = setTimeout(()=>controller.abort(), timeoutMs);
|
|
90
|
-
return {
|
|
91
|
-
signal: controller.signal,
|
|
92
|
-
clear: ()=>clearTimeout(timer)
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
const createHttpContractGateSnapshotStore = (options)=>{
|
|
96
|
-
const normalized = normalizeHttpStoreOptions(options);
|
|
97
|
-
const endpoint = normalized.endpoint;
|
|
98
|
-
return {
|
|
99
|
-
name: `http:${endpoint}`,
|
|
100
|
-
async readSnapshot () {
|
|
101
|
-
const { signal, clear } = withTimeoutAbort(normalized.timeoutMs || 5000);
|
|
102
|
-
try {
|
|
103
|
-
const response = await fetch(endpoint, {
|
|
104
|
-
method: normalized.readMethod || 'GET',
|
|
105
|
-
headers: {
|
|
106
|
-
accept: 'application/json',
|
|
107
|
-
...normalized.headers || {}
|
|
108
|
-
},
|
|
109
|
-
signal
|
|
110
|
-
});
|
|
111
|
-
if (404 === response.status) return;
|
|
112
|
-
if (!response.ok) throw new Error(`HTTP stateStore read failed with status ${String(response.status)}`);
|
|
113
|
-
const payload = await response.json();
|
|
114
|
-
return normalizeSnapshot(payload);
|
|
115
|
-
} finally{
|
|
116
|
-
clear();
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
async writeSnapshot (snapshot) {
|
|
120
|
-
const body = JSON.stringify(normalizeSnapshot(snapshot) || {
|
|
121
|
-
schemaVersion: CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION,
|
|
122
|
-
updatedAt: Date.now(),
|
|
123
|
-
gates: {}
|
|
124
|
-
});
|
|
125
|
-
const { signal, clear } = withTimeoutAbort(normalized.timeoutMs || 5000);
|
|
126
|
-
try {
|
|
127
|
-
const response = await fetch(endpoint, {
|
|
128
|
-
method: normalized.writeMethod || 'PUT',
|
|
129
|
-
headers: {
|
|
130
|
-
'content-type': 'application/json',
|
|
131
|
-
...normalized.headers || {}
|
|
132
|
-
},
|
|
133
|
-
body,
|
|
134
|
-
signal
|
|
135
|
-
});
|
|
136
|
-
if (!response.ok) throw new Error(`HTTP stateStore write failed with status ${String(response.status)}`);
|
|
137
|
-
} finally{
|
|
138
|
-
clear();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
};
|
|
143
|
-
const tryResolveBuiltinSnapshotStore = (input)=>{
|
|
144
|
-
const moduleName = input.stateStore.module.trim();
|
|
145
|
-
if (!BUILTIN_HTTP_STATE_STORE_MODULES.has(moduleName)) return;
|
|
146
|
-
return createHttpContractGateSnapshotStore(input.stateStore.options || {});
|
|
147
|
-
};
|
|
148
|
-
const pickStoreFactory = (mod)=>{
|
|
149
|
-
if ('function' == typeof mod) return mod;
|
|
150
|
-
if ('function' == typeof mod.createContractGateSnapshotStore) return mod.createContractGateSnapshotStore;
|
|
151
|
-
if ('function' == typeof mod.default) return mod.default;
|
|
152
|
-
if (mod.default && 'object' == typeof mod.default && 'function' == typeof mod.default.createContractGateSnapshotStore) return mod.default.createContractGateSnapshotStore;
|
|
153
|
-
};
|
|
154
|
-
const ensureStoreShape = (store, modulePath)=>{
|
|
155
|
-
if (!store || 'object' != typeof store || 'function' != typeof store.readSnapshot || 'function' != typeof store.writeSnapshot) throw new Error(`Invalid contract gate snapshot store from "${modulePath}". Expected { readSnapshot(), writeSnapshot() }.`);
|
|
156
|
-
};
|
|
157
|
-
const resolveStoreModulePath = (appDirectory, modulePath)=>{
|
|
158
|
-
const normalized = modulePath.trim();
|
|
159
|
-
if (!normalized) throw new Error('Contract gate snapshot stateStore.module must be non-empty');
|
|
160
|
-
if (external_path_default().isAbsolute(normalized)) return normalized;
|
|
161
|
-
return normalized.startsWith('.') ? external_path_default().resolve(appDirectory, normalized) : normalized;
|
|
162
|
-
};
|
|
163
|
-
const resolveContractGateSnapshotPath = (appDirectory, configuredPath)=>{
|
|
164
|
-
const rawPath = configuredPath || process.env.MODERN_CONTRACT_GATES_FILE || DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH;
|
|
165
|
-
if (external_path_default().isAbsolute(rawPath)) return rawPath;
|
|
166
|
-
return external_path_default().resolve(appDirectory, rawPath);
|
|
167
|
-
};
|
|
168
|
-
const createFileContractGateSnapshotStore = (gateSnapshotPath)=>{
|
|
169
|
-
const resolvedPath = external_path_default().resolve(gateSnapshotPath);
|
|
170
|
-
return {
|
|
171
|
-
name: `file:${resolvedPath}`,
|
|
172
|
-
async readSnapshot () {
|
|
173
|
-
if (!await utils_namespaceObject.fs.pathExists(resolvedPath)) return;
|
|
174
|
-
try {
|
|
175
|
-
const raw = await external_fs_namespaceObject.promises.readFile(resolvedPath, 'utf8');
|
|
176
|
-
return normalizeSnapshot(JSON.parse(raw));
|
|
177
|
-
} catch (_error) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
async writeSnapshot (snapshot) {
|
|
182
|
-
const normalized = normalizeSnapshot(snapshot) || {
|
|
183
|
-
schemaVersion: CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION,
|
|
184
|
-
updatedAt: Date.now(),
|
|
185
|
-
gates: {}
|
|
186
|
-
};
|
|
187
|
-
await external_fs_namespaceObject.promises.mkdir(external_path_default().dirname(resolvedPath), {
|
|
188
|
-
recursive: true
|
|
189
|
-
});
|
|
190
|
-
await external_fs_namespaceObject.promises.writeFile(resolvedPath, `${JSON.stringify(normalized, null, 2)}\n`);
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
const resolveContractGateSnapshotStore = async (input)=>{
|
|
195
|
-
const { appDirectory, gateSnapshotPath, stateStore, logger } = input;
|
|
196
|
-
if (!stateStore?.module) return createFileContractGateSnapshotStore(gateSnapshotPath);
|
|
197
|
-
const builtinStore = tryResolveBuiltinSnapshotStore({
|
|
198
|
-
stateStore
|
|
199
|
-
});
|
|
200
|
-
if (builtinStore) {
|
|
201
|
-
logger?.info?.(`[telemetry.canary.autopilot] using built-in contract gate snapshot store "${builtinStore.name}"`);
|
|
202
|
-
return builtinStore;
|
|
203
|
-
}
|
|
204
|
-
const modulePath = resolveStoreModulePath(appDirectory, stateStore.module);
|
|
205
|
-
let mod;
|
|
206
|
-
try {
|
|
207
|
-
mod = require(modulePath);
|
|
208
|
-
} catch (error) {
|
|
209
|
-
throw new Error(`[telemetry.canary.autopilot] Failed to load stateStore.module "${stateStore.module}" (${modulePath}): ${error instanceof Error ? error.message : String(error)}`);
|
|
210
|
-
}
|
|
211
|
-
const factory = pickStoreFactory(mod);
|
|
212
|
-
if (!factory) throw new Error(`[telemetry.canary.autopilot] stateStore.module "${stateStore.module}" does not export createContractGateSnapshotStore()`);
|
|
213
|
-
const store = await factory({
|
|
214
|
-
appDirectory,
|
|
215
|
-
gateSnapshotPath,
|
|
216
|
-
options: stateStore.options,
|
|
217
|
-
logger
|
|
218
|
-
});
|
|
219
|
-
ensureStoreShape(store, modulePath);
|
|
220
|
-
logger?.info?.(`[telemetry.canary.autopilot] using contract gate snapshot store "${store.name || modulePath}"`);
|
|
221
|
-
return store;
|
|
222
|
-
};
|
|
223
|
-
exports.CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION = __webpack_exports__.CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION;
|
|
224
|
-
exports.DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH = __webpack_exports__.DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH;
|
|
225
|
-
exports.createFileContractGateSnapshotStore = __webpack_exports__.createFileContractGateSnapshotStore;
|
|
226
|
-
exports.createHttpContractGateSnapshotStore = __webpack_exports__.createHttpContractGateSnapshotStore;
|
|
227
|
-
exports.resolveContractGateSnapshotPath = __webpack_exports__.resolveContractGateSnapshotPath;
|
|
228
|
-
exports.resolveContractGateSnapshotStore = __webpack_exports__.resolveContractGateSnapshotStore;
|
|
229
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
230
|
-
"CONTRACT_GATE_SNAPSHOT_SCHEMA_VERSION",
|
|
231
|
-
"DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH",
|
|
232
|
-
"createFileContractGateSnapshotStore",
|
|
233
|
-
"createHttpContractGateSnapshotStore",
|
|
234
|
-
"resolveContractGateSnapshotPath",
|
|
235
|
-
"resolveContractGateSnapshotStore"
|
|
236
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
237
|
-
Object.defineProperty(exports, '__esModule', {
|
|
238
|
-
value: true
|
|
239
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: definition[key]
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
})();
|
|
11
|
-
(()=>{
|
|
12
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
-
})();
|
|
14
|
-
(()=>{
|
|
15
|
-
__webpack_require__.r = (exports1)=>{
|
|
16
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
-
value: 'Module'
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
-
value: true
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
var __webpack_exports__ = {};
|
|
25
|
-
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
getRequestPathname: ()=>getRequestPathname,
|
|
28
|
-
isMfManifestAsset: ()=>isMfManifestAsset,
|
|
29
|
-
isMfRemoteEntryAsset: ()=>isMfRemoteEntryAsset,
|
|
30
|
-
resolveMfAssetCacheHeaders: ()=>resolveMfAssetCacheHeaders
|
|
31
|
-
});
|
|
32
|
-
const REMOTE_ENTRY_REGEXP = /(^|\/)remoteEntry(?:\.[a-zA-Z0-9_-]+)?\.js$/;
|
|
33
|
-
function firstQueryValue(value) {
|
|
34
|
-
if (Array.isArray(value)) return value.find((item)=>'string' == typeof item && item.length > 0);
|
|
35
|
-
if ('string' == typeof value && value.length > 0) return value;
|
|
36
|
-
}
|
|
37
|
-
function getRequestPathname(url) {
|
|
38
|
-
try {
|
|
39
|
-
return new URL(url, 'http://modernjs.local').pathname;
|
|
40
|
-
} catch (_error) {
|
|
41
|
-
return url.split('?')[0] || '/';
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function isMfManifestAsset(pathname) {
|
|
45
|
-
return pathname.endsWith('/mf-manifest.json') || pathname.endsWith('/mf-stats.json');
|
|
46
|
-
}
|
|
47
|
-
function isMfRemoteEntryAsset(pathname) {
|
|
48
|
-
return REMOTE_ENTRY_REGEXP.test(pathname);
|
|
49
|
-
}
|
|
50
|
-
function hasRemoteVersionPin(query = {}) {
|
|
51
|
-
return Boolean(firstQueryValue(query.mfv) || firstQueryValue(query.v) || firstQueryValue(query.version));
|
|
52
|
-
}
|
|
53
|
-
function resolveMfAssetCacheHeaders(url, query = {}) {
|
|
54
|
-
const pathname = getRequestPathname(url);
|
|
55
|
-
if (isMfManifestAsset(pathname)) return {
|
|
56
|
-
'cache-control': 'no-cache, no-store, must-revalidate',
|
|
57
|
-
pragma: 'no-cache',
|
|
58
|
-
expires: '0'
|
|
59
|
-
};
|
|
60
|
-
if (isMfRemoteEntryAsset(pathname)) return hasRemoteVersionPin(query) ? {
|
|
61
|
-
'cache-control': 'public, max-age=31536000, immutable'
|
|
62
|
-
} : {
|
|
63
|
-
'cache-control': 'public, max-age=0, must-revalidate'
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
exports.getRequestPathname = __webpack_exports__.getRequestPathname;
|
|
67
|
-
exports.isMfManifestAsset = __webpack_exports__.isMfManifestAsset;
|
|
68
|
-
exports.isMfRemoteEntryAsset = __webpack_exports__.isMfRemoteEntryAsset;
|
|
69
|
-
exports.resolveMfAssetCacheHeaders = __webpack_exports__.resolveMfAssetCacheHeaders;
|
|
70
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
71
|
-
"getRequestPathname",
|
|
72
|
-
"isMfManifestAsset",
|
|
73
|
-
"isMfRemoteEntryAsset",
|
|
74
|
-
"resolveMfAssetCacheHeaders"
|
|
75
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
76
|
-
Object.defineProperty(exports, '__esModule', {
|
|
77
|
-
value: true
|
|
78
|
-
});
|