@tradejs/cli 3.1.29-beta.262 → 3.1.29-beta.264
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/cli.js +864 -1424
- package/dist/lib/runtimeEvidenceArtifacts.js +3 -416
- package/dist/lib/runtimeEvidenceCompositionSnapshots.js +42 -211
- package/dist/lib/runtimeEvidenceCompositions.js +33 -310
- package/dist/lib/runtimeEvidenceDeployment.js +3 -315
- package/dist/lib/runtimeEvidenceProducer.js +3 -77
- package/dist/lib/runtimeEvidenceSync.js +32 -299
- package/dist/lib/runtimeFeedbackArtifacts.js +3 -545
- package/dist/lib/runtimeFeedbackNotification.js +7 -195
- package/dist/lib/runtimeFeedbackReplay.js +26 -525
- package/dist/lib/runtimeFeedbackSync.js +26 -219
- package/dist/lib/runtimeScorecard.js +5 -163
- package/dist/scripts/backtest.js +6 -1
- package/dist/scripts/mcpWorker.js +273 -0
- package/dist/scripts/replay.js +14 -250
- package/dist/scripts/replayRunner.js +14 -250
- package/dist/scripts/runtimeEvidence.js +47 -597
- package/dist/scripts/runtimeEvidenceSync.js +29 -296
- package/dist/scripts/runtimeFeedbackNotify.js +10 -188
- package/dist/scripts/runtimeFeedbackReplay.js +29 -528
- package/dist/scripts/runtimeFeedbackSync.js +28 -221
- package/dist/scripts/runtimeScorecard.js +88 -503
- package/dist/scripts/signals.js +55 -224
- package/dist/scripts/signalsDaemon.js +55 -224
- package/package.json +7 -7
|
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
6
|
var __copyProps = (to, from, except, desc) => {
|
|
11
7
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
8
|
for (let key of __getOwnPropNames(from))
|
|
@@ -15,322 +11,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
11
|
}
|
|
16
12
|
return to;
|
|
17
13
|
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
16
|
|
|
20
17
|
// src/lib/runtimeEvidenceDeployment.ts
|
|
21
18
|
var runtimeEvidenceDeployment_exports = {};
|
|
22
|
-
__export(runtimeEvidenceDeployment_exports, {
|
|
23
|
-
activeRuntimeEvidenceStrategies: () => activeRuntimeEvidenceStrategies,
|
|
24
|
-
assertCurrentRuntimeEvidenceArtifact: () => assertCurrentRuntimeEvidenceArtifact,
|
|
25
|
-
parseRuntimeEvidenceDeploymentSnapshot: () => parseRuntimeEvidenceDeploymentSnapshot,
|
|
26
|
-
resolveRuntimeEvidenceDeploymentSnapshot: () => resolveRuntimeEvidenceDeploymentSnapshot,
|
|
27
|
-
resolveRuntimeEvidenceTickerUniverse: () => resolveRuntimeEvidenceTickerUniverse,
|
|
28
|
-
runtimeDeploymentFromEvidence: () => runtimeDeploymentFromEvidence,
|
|
29
|
-
runtimeLineageMatchesStrategySnapshot: () => runtimeLineageMatchesStrategySnapshot
|
|
30
|
-
});
|
|
31
19
|
module.exports = __toCommonJS(runtimeEvidenceDeployment_exports);
|
|
32
|
-
|
|
33
|
-
var isRecord = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
34
|
-
var isNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
35
|
-
var isPackageVersionMap = (value) => isRecord(value) && Object.keys(value).length > 0 && Object.entries(value).every(
|
|
36
|
-
([name, version]) => name.startsWith("@tradejs/") && isNonEmptyString(version)
|
|
37
|
-
);
|
|
38
|
-
var INTERVALS = /* @__PURE__ */ new Set([
|
|
39
|
-
"1",
|
|
40
|
-
"3",
|
|
41
|
-
"5",
|
|
42
|
-
"15",
|
|
43
|
-
"30",
|
|
44
|
-
"60",
|
|
45
|
-
"120",
|
|
46
|
-
"240",
|
|
47
|
-
"360",
|
|
48
|
-
"720",
|
|
49
|
-
"D",
|
|
50
|
-
"W",
|
|
51
|
-
"M"
|
|
52
|
-
]);
|
|
53
|
-
var UNIVERSES = /* @__PURE__ */ new Set(["crypto", "tradfi"]);
|
|
54
|
-
var isRuntimeStrategySelection = (value) => value === void 0 || isRecord(value) && Object.keys(value).length === 1 && Object.keys(value).every((key) => key === "tickers") && Array.isArray(value.tickers) && value.tickers.length > 0 && value.tickers.every((ticker) => isNonEmptyString(ticker));
|
|
55
|
-
var samePackageVersions = (left, right) => {
|
|
56
|
-
if (!left || !right) return false;
|
|
57
|
-
const leftEntries = Object.entries(left).sort(
|
|
58
|
-
([a], [b]) => a.localeCompare(b)
|
|
59
|
-
);
|
|
60
|
-
const rightEntries = Object.entries(right).sort(
|
|
61
|
-
([a], [b]) => a.localeCompare(b)
|
|
62
|
-
);
|
|
63
|
-
return JSON.stringify(leftEntries) === JSON.stringify(rightEntries);
|
|
64
|
-
};
|
|
65
|
-
var runtimeLineageMatchesStrategySnapshot = ({
|
|
66
|
-
lineage,
|
|
67
|
-
deployment,
|
|
68
|
-
strategy
|
|
69
|
-
}) => lineage?.schemaVersion === 3 && lineage.strategyRevision === strategy.strategyRevision && lineage.deploymentCompositionId === deployment.deploymentCompositionId && lineage.strategyPackageVersion === strategy.strategyPackageVersion && lineage.runtimePackageVersion === strategy.runtimePackageVersion && samePackageVersions(
|
|
70
|
-
lineage.strategyDependencyVersions,
|
|
71
|
-
strategy.strategyDependencyVersions
|
|
72
|
-
);
|
|
73
|
-
var parseRuntimeEvidenceDeploymentSnapshot = (value) => {
|
|
74
|
-
if (!isRecord(value) || value.schemaVersion !== 2 || !isNonEmptyString(value.id) || !isNonEmptyString(value.deploymentCompositionId) || !/^dc1:[a-f0-9]{16}$/.test(value.deploymentCompositionId) || !isNonEmptyString(value.label) || !isNonEmptyString(value.connectorName) || !isNonEmptyString(value.provider) || !isNonEmptyString(value.accountId) || typeof value.enabled !== "boolean" || !Array.isArray(value.strategies)) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
"Runtime evidence deployment snapshot is missing or invalid"
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
const strategies = value.strategies.map((candidate) => {
|
|
80
|
-
if (!isRecord(candidate) || !isNonEmptyString(candidate.strategyName) || !isNonEmptyString(candidate.strategyRevision) || !/^sr1:[a-f0-9]{16}$/.test(candidate.strategyRevision) || typeof candidate.enabled !== "boolean" || !["active", "entries_paused"].includes(String(candidate.controlState)) || !INTERVALS.has(String(candidate.interval)) || !UNIVERSES.has(String(candidate.universe)) || !isNonEmptyString(candidate.strategyPackage) || !isNonEmptyString(candidate.strategyPackageVersion) || !isPackageVersionMap(candidate.strategyDependencyVersions) || !isNonEmptyString(candidate.runtimePackageVersion) || !isRecord(candidate.strategyConfig) || !isRuntimeStrategySelection(candidate.selection)) {
|
|
81
|
-
throw new Error(
|
|
82
|
-
"Runtime evidence deployment strategy snapshot is invalid"
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
if (String(candidate.strategyConfig.INTERVAL) !== String(candidate.interval) || String(candidate.strategyConfig.UNIVERSE) !== String(candidate.universe)) {
|
|
86
|
-
throw new Error(
|
|
87
|
-
`Runtime evidence strategy config does not match its scope: ${candidate.strategyName}`
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
if (candidate.accountId != null && (!isNonEmptyString(candidate.accountId) || candidate.accountId !== value.accountId)) {
|
|
91
|
-
throw new Error(
|
|
92
|
-
`Runtime evidence strategy account does not match deployment: ${candidate.strategyName}`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
return candidate;
|
|
96
|
-
});
|
|
97
|
-
const identities = /* @__PURE__ */ new Set();
|
|
98
|
-
for (const strategy of strategies) {
|
|
99
|
-
if (identities.has(strategy.strategyName)) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
`Duplicate runtime evidence strategy: ${strategy.strategyName}`
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
identities.add(strategy.strategyName);
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
...value,
|
|
108
|
-
strategies
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
var activeRuntimeEvidenceStrategies = (deployment) => deployment.enabled ? deployment.strategies.filter((strategy) => strategy.enabled) : [];
|
|
112
|
-
var unwrapRuntimeEvidenceRows = (value, field) => (Array.isArray(value) ? value : []).map((candidate) => {
|
|
113
|
-
const record = isRecord(candidate) ? candidate : null;
|
|
114
|
-
const nested = record && isRecord(record[field]) ? record[field] : null;
|
|
115
|
-
return nested ?? record;
|
|
116
|
-
}).filter((record) => record != null);
|
|
117
|
-
var assertCurrentRuntimeEvidenceArtifact = (artifact) => {
|
|
118
|
-
if (!isRecord(artifact) || artifact.reportType !== "runtime-evidence") {
|
|
119
|
-
throw new Error("Invalid runtime evidence artifact");
|
|
120
|
-
}
|
|
121
|
-
const deployment = parseRuntimeEvidenceDeploymentSnapshot(
|
|
122
|
-
artifact.deployment
|
|
123
|
-
);
|
|
124
|
-
const activeStrategies = activeRuntimeEvidenceStrategies(deployment);
|
|
125
|
-
if (activeStrategies.length === 0) {
|
|
126
|
-
throw new Error("Runtime evidence deployment has no enabled strategies");
|
|
127
|
-
}
|
|
128
|
-
const runtime = isRecord(artifact.runtime) ? artifact.runtime : null;
|
|
129
|
-
if (!runtime) {
|
|
130
|
-
throw new Error("Runtime evidence payload is missing");
|
|
131
|
-
}
|
|
132
|
-
if ("strategyConfigs" in runtime) {
|
|
133
|
-
throw new Error(
|
|
134
|
-
"Runtime evidence payload contains removed strategyConfigs data"
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
if ("evaluationStatsBuckets" in runtime) {
|
|
138
|
-
throw new Error(
|
|
139
|
-
"Runtime evidence payload contains removed lineage-less evaluationStatsBuckets data"
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
const rowFields = [
|
|
143
|
-
"trades",
|
|
144
|
-
"signals",
|
|
145
|
-
"evaluations",
|
|
146
|
-
"lineageScopes"
|
|
147
|
-
];
|
|
148
|
-
for (const field of rowFields) {
|
|
149
|
-
if (!Array.isArray(runtime[field])) {
|
|
150
|
-
throw new Error(`Runtime evidence payload ${field} must be an array`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
const snapshots = new Map(
|
|
154
|
-
activeStrategies.map((strategy) => [strategy.strategyName, strategy])
|
|
155
|
-
);
|
|
156
|
-
const assertRows = (label, rows, lineageField) => {
|
|
157
|
-
for (const row of rows) {
|
|
158
|
-
const strategyName = String(row.strategy ?? "").trim();
|
|
159
|
-
const strategy = snapshots.get(strategyName);
|
|
160
|
-
if (!strategy || row.deploymentId !== deployment.id || row.accountId !== deployment.accountId || !runtimeLineageMatchesStrategySnapshot({
|
|
161
|
-
lineage: isRecord(row[lineageField]) ? row[lineageField] : void 0,
|
|
162
|
-
deployment,
|
|
163
|
-
strategy
|
|
164
|
-
})) {
|
|
165
|
-
throw new Error(
|
|
166
|
-
`Runtime evidence ${label} row is outside the current embedded deployment lineage`
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
assertRows(
|
|
172
|
-
"trade",
|
|
173
|
-
unwrapRuntimeEvidenceRows(runtime.trades, "trade"),
|
|
174
|
-
"runtimeLineage"
|
|
175
|
-
);
|
|
176
|
-
assertRows(
|
|
177
|
-
"signal",
|
|
178
|
-
unwrapRuntimeEvidenceRows(runtime.signals, "signal"),
|
|
179
|
-
"runtimeLineage"
|
|
180
|
-
);
|
|
181
|
-
assertRows(
|
|
182
|
-
"evaluation",
|
|
183
|
-
unwrapRuntimeEvidenceRows(runtime.evaluations, "evaluation"),
|
|
184
|
-
"runtimeLineage"
|
|
185
|
-
);
|
|
186
|
-
assertRows(
|
|
187
|
-
"lineage scope",
|
|
188
|
-
unwrapRuntimeEvidenceRows(runtime.lineageScopes, "lineageScope"),
|
|
189
|
-
"lineage"
|
|
190
|
-
);
|
|
191
|
-
return deployment;
|
|
192
|
-
};
|
|
193
|
-
var resolveRuntimeEvidenceTickerUniverse = ({
|
|
194
|
-
deployment,
|
|
195
|
-
lineageScopes,
|
|
196
|
-
fallbackTickers
|
|
197
|
-
}) => {
|
|
198
|
-
const declaredTickers = deployment.tickers?.filter(isNonEmptyString) ?? [];
|
|
199
|
-
if (declaredTickers.length > 0) {
|
|
200
|
-
return {
|
|
201
|
-
...deployment,
|
|
202
|
-
tickers: [
|
|
203
|
-
...new Set(declaredTickers.map((ticker) => ticker.trim()))
|
|
204
|
-
].sort()
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
const activeStrategies = activeRuntimeEvidenceStrategies(deployment);
|
|
208
|
-
if (activeStrategies.length > 0 && activeStrategies.every((strategy) => strategy.selection?.tickers?.length)) {
|
|
209
|
-
return {
|
|
210
|
-
...deployment,
|
|
211
|
-
tickers: [
|
|
212
|
-
...new Set(
|
|
213
|
-
activeStrategies.flatMap(
|
|
214
|
-
(strategy) => strategy.selection?.tickers ?? []
|
|
215
|
-
)
|
|
216
|
-
)
|
|
217
|
-
].sort()
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
const strategiesByName = new Map(
|
|
221
|
-
activeStrategies.map((strategy) => [strategy.strategyName, strategy])
|
|
222
|
-
);
|
|
223
|
-
const tickers = /* @__PURE__ */ new Set();
|
|
224
|
-
for (const scope of lineageScopes) {
|
|
225
|
-
const strategy = strategiesByName.get(scope.strategy);
|
|
226
|
-
if (!strategy || scope.deploymentId !== deployment.id || scope.accountId !== deployment.accountId || !isNonEmptyString(scope.symbol) || !runtimeLineageMatchesStrategySnapshot({
|
|
227
|
-
lineage: scope.lineage,
|
|
228
|
-
deployment,
|
|
229
|
-
strategy
|
|
230
|
-
})) {
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
tickers.add(scope.symbol.trim());
|
|
234
|
-
}
|
|
235
|
-
if (tickers.size === 0) {
|
|
236
|
-
const verifiedFallbackTickers = fallbackTickers?.filter(isNonEmptyString) ?? [];
|
|
237
|
-
if (verifiedFallbackTickers.length > 0) {
|
|
238
|
-
return {
|
|
239
|
-
...deployment,
|
|
240
|
-
tickers: [
|
|
241
|
-
...new Set(verifiedFallbackTickers.map((ticker) => ticker.trim()))
|
|
242
|
-
].sort()
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
throw new Error(
|
|
246
|
-
"Runtime evidence has no immutable ticker universe for the embedded deployment composition"
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
return { ...deployment, tickers: [...tickers].sort() };
|
|
250
|
-
};
|
|
251
|
-
var runtimeDeploymentFromEvidence = (deployment) => ({
|
|
252
|
-
id: deployment.id,
|
|
253
|
-
deploymentCompositionId: deployment.deploymentCompositionId,
|
|
254
|
-
label: deployment.label,
|
|
255
|
-
connectorName: deployment.connectorName,
|
|
256
|
-
provider: deployment.provider,
|
|
257
|
-
accountId: deployment.accountId,
|
|
258
|
-
enabled: deployment.enabled,
|
|
259
|
-
strategies: deployment.strategies.map(
|
|
260
|
-
({ strategyName, strategyRevision, enabled, controlState, selection }) => ({
|
|
261
|
-
strategyName,
|
|
262
|
-
strategyRevision,
|
|
263
|
-
enabled,
|
|
264
|
-
controlState,
|
|
265
|
-
...selection ? { selection } : {}
|
|
266
|
-
})
|
|
267
|
-
),
|
|
268
|
-
...deployment.assetClasses ? { assetClasses: [...deployment.assetClasses] } : {},
|
|
269
|
-
...deployment.tickers ? { tickers: [...deployment.tickers] } : {}
|
|
270
|
-
});
|
|
271
|
-
var resolveRuntimeEvidenceDeploymentSnapshot = async ({
|
|
272
|
-
userName,
|
|
273
|
-
projectRoot,
|
|
274
|
-
deploymentId
|
|
275
|
-
}) => {
|
|
276
|
-
const [deployment, strategies] = await Promise.all([
|
|
277
|
-
(0, import_runtimeStrategies.getRuntimeDeployment)({ userName, projectRoot, deploymentId }),
|
|
278
|
-
(0, import_runtimeStrategies.loadResolvedRuntimeStrategies)({ userName, projectRoot, deploymentId })
|
|
279
|
-
]);
|
|
280
|
-
if (!deployment) {
|
|
281
|
-
throw new Error(`Runtime deployment not found: ${deploymentId}`);
|
|
282
|
-
}
|
|
283
|
-
return {
|
|
284
|
-
schemaVersion: 2,
|
|
285
|
-
id: deployment.id,
|
|
286
|
-
deploymentCompositionId: deployment.deploymentCompositionId,
|
|
287
|
-
label: deployment.label,
|
|
288
|
-
connectorName: deployment.connectorName,
|
|
289
|
-
provider: deployment.provider,
|
|
290
|
-
accountId: deployment.accountId,
|
|
291
|
-
enabled: deployment.enabled,
|
|
292
|
-
strategies: strategies.map(
|
|
293
|
-
({
|
|
294
|
-
strategyName,
|
|
295
|
-
strategyRevision,
|
|
296
|
-
enabled,
|
|
297
|
-
controlState,
|
|
298
|
-
interval,
|
|
299
|
-
universe,
|
|
300
|
-
accountId,
|
|
301
|
-
strategyPackage,
|
|
302
|
-
strategyPackageVersion,
|
|
303
|
-
strategyDependencyVersions,
|
|
304
|
-
runtimePackageVersion,
|
|
305
|
-
strategyConfig,
|
|
306
|
-
selection
|
|
307
|
-
}) => ({
|
|
308
|
-
strategyName,
|
|
309
|
-
strategyRevision,
|
|
310
|
-
enabled,
|
|
311
|
-
controlState,
|
|
312
|
-
interval,
|
|
313
|
-
universe,
|
|
314
|
-
...accountId ? { accountId } : {},
|
|
315
|
-
strategyPackage,
|
|
316
|
-
strategyPackageVersion,
|
|
317
|
-
strategyDependencyVersions,
|
|
318
|
-
runtimePackageVersion,
|
|
319
|
-
strategyConfig,
|
|
320
|
-
...selection ? { selection } : {}
|
|
321
|
-
})
|
|
322
|
-
),
|
|
323
|
-
...deployment.assetClasses ? { assetClasses: [...deployment.assetClasses] } : {},
|
|
324
|
-
...deployment.tickers ? { tickers: [...deployment.tickers] } : {}
|
|
325
|
-
};
|
|
326
|
-
};
|
|
20
|
+
__reExport(runtimeEvidenceDeployment_exports, require("@tradejs/node/diagnostics"), module.exports);
|
|
327
21
|
// Annotate the CommonJS export names for ESM import in node:
|
|
328
22
|
0 && (module.exports = {
|
|
329
|
-
|
|
330
|
-
assertCurrentRuntimeEvidenceArtifact,
|
|
331
|
-
parseRuntimeEvidenceDeploymentSnapshot,
|
|
332
|
-
resolveRuntimeEvidenceDeploymentSnapshot,
|
|
333
|
-
resolveRuntimeEvidenceTickerUniverse,
|
|
334
|
-
runtimeDeploymentFromEvidence,
|
|
335
|
-
runtimeLineageMatchesStrategySnapshot
|
|
23
|
+
...require("@tradejs/node/diagnostics")
|
|
336
24
|
});
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
6
|
var __copyProps = (to, from, except, desc) => {
|
|
13
7
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
8
|
for (let key of __getOwnPropNames(from))
|
|
@@ -17,82 +11,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
11
|
}
|
|
18
12
|
return to;
|
|
19
13
|
};
|
|
20
|
-
var
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
28
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
16
|
|
|
30
17
|
// src/lib/runtimeEvidenceProducer.ts
|
|
31
18
|
var runtimeEvidenceProducer_exports = {};
|
|
32
|
-
__export(runtimeEvidenceProducer_exports, {
|
|
33
|
-
parseRuntimeEvidenceProducer: () => parseRuntimeEvidenceProducer,
|
|
34
|
-
resolveRuntimeEvidenceProducer: () => resolveRuntimeEvidenceProducer
|
|
35
|
-
});
|
|
36
19
|
module.exports = __toCommonJS(runtimeEvidenceProducer_exports);
|
|
37
|
-
|
|
38
|
-
var import_promises = __toESM(require("fs/promises"));
|
|
39
|
-
var import_node_path = __toESM(require("path"));
|
|
40
|
-
var isRecord = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
41
|
-
var sha256 = (value) => (0, import_node_crypto.createHash)("sha256").update(value).digest("hex");
|
|
42
|
-
var parseRuntimeEvidenceProducer = (value) => {
|
|
43
|
-
const producer = isRecord(value) ? value : null;
|
|
44
|
-
const runtimePackageManifest = isRecord(producer?.runtimePackageManifest) ? producer.runtimePackageManifest : null;
|
|
45
|
-
if (producer?.schemaVersion !== 1 || typeof producer.projectSha !== "string" || !/^[a-f0-9]{40}$/.test(producer.projectSha) || typeof producer.imageDigest !== "string" || !/^sha256:[a-f0-9]{64}$/.test(producer.imageDigest) || runtimePackageManifest?.file !== "runtime-package-manifest.json" || typeof runtimePackageManifest.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(runtimePackageManifest.sha256)) {
|
|
46
|
-
throw new Error("Runtime evidence producer image identity is invalid");
|
|
47
|
-
}
|
|
48
|
-
return producer;
|
|
49
|
-
};
|
|
50
|
-
var resolveRuntimeEvidenceProducer = async ({
|
|
51
|
-
projectRoot,
|
|
52
|
-
required
|
|
53
|
-
}) => {
|
|
54
|
-
const projectSha = String(process.env.TRADEJS_PROJECT_SHA ?? "").trim();
|
|
55
|
-
const imageDigest = String(
|
|
56
|
-
process.env.TRADEJS_PROJECT_IMAGE_DIGEST ?? ""
|
|
57
|
-
).trim();
|
|
58
|
-
if (!projectSha && !imageDigest && !required) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
if (!/^[a-f0-9]{40}$/.test(projectSha)) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
"TRADEJS_PROJECT_SHA must be a full lowercase Git SHA before publishing runtime evidence"
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
if (!/^sha256:[a-f0-9]{64}$/.test(imageDigest)) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
"TRADEJS_PROJECT_IMAGE_DIGEST must be an immutable sha256 digest before publishing runtime evidence"
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
const manifestPath = import_node_path.default.join(projectRoot, "runtime-package-manifest.json");
|
|
72
|
-
let manifest;
|
|
73
|
-
try {
|
|
74
|
-
manifest = await import_promises.default.readFile(manifestPath);
|
|
75
|
-
} catch (error) {
|
|
76
|
-
if (!required && error.code === "ENOENT") {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
throw new Error(
|
|
80
|
-
`Runtime package manifest is required for runtime evidence: ${manifestPath}`,
|
|
81
|
-
{ cause: error }
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
schemaVersion: 1,
|
|
86
|
-
projectSha,
|
|
87
|
-
imageDigest,
|
|
88
|
-
runtimePackageManifest: {
|
|
89
|
-
file: "runtime-package-manifest.json",
|
|
90
|
-
sha256: sha256(manifest)
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
};
|
|
20
|
+
__reExport(runtimeEvidenceProducer_exports, require("@tradejs/node/diagnostics"), module.exports);
|
|
94
21
|
// Annotate the CommonJS export names for ESM import in node:
|
|
95
22
|
0 && (module.exports = {
|
|
96
|
-
|
|
97
|
-
resolveRuntimeEvidenceProducer
|
|
23
|
+
...require("@tradejs/node/diagnostics")
|
|
98
24
|
});
|