Intelligence, Advanced Charting & Trading Platform

1 const REQUIRED = Object.freeze(['GOLD18_IRT', 'USD_IRT_FREE', 'XAU_USD']);
2
3 export function buildDataProofArtifact({ generatedAt, reports }) {
4 if (!(generatedAt instanceof Date) || Number.isNaN(generatedAt.valueOf())) throw new TypeError('generatedAt must be a valid Date');
5 if (!Array.isArray(reports)) throw new TypeError('reports must be an array');
6
7 const seen = new Set();
8 for (const report of reports) {
9 if (!report || typeof report !== 'object') throw new TypeError('each report must be an object');
10 if (!report.providerCode || !report.canonicalSymbol) throw new TypeError('report providerCode and canonicalSymbol are required');
11 if (!['PASS', 'FAIL'].includes(report.status)) throw new RangeError('report status must be PASS or FAIL');
12 if (seen.has(report.canonicalSymbol)) throw new RangeError(`duplicate report for ${report.canonicalSymbol}`);
13 seen.add(report.canonicalSymbol);
14 const checked = new Date(report.checkedAt);
15 if (Number.isNaN(checked.valueOf())) throw new TypeError('report checkedAt must be valid');
16 if (checked > generatedAt) throw new RangeError('report checkedAt cannot be after generatedAt');
17 }
18
19 const missing = REQUIRED.filter(symbol => !seen.has(symbol));
20 if (missing.length) throw new RangeError(`required Phase 1 reports missing: ${missing.join(', ')}`);
21
22 const requiredReports = reports
23 .filter(report => REQUIRED.includes(report.canonicalSymbol))
24 .sort((a, b) => a.canonicalSymbol.localeCompare(b.canonicalSymbol));
25
26 return Object.freeze({
27 phase: 1,
28 generatedAt: generatedAt.toISOString(),
29 status: requiredReports.every(report => report.status === 'PASS') ? 'PASS' : 'FAIL',
30 requiredSymbols: [...REQUIRED],
31 reports: requiredReports.map(report => Object.freeze({ ...report })),
32 });
33 }