// Copyright (C) 2025 Keygraph, Inc. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License version 3 // as published by the Free Software Foundation. /** * Queue Validator * * Validates JSON structure for vulnerability queue files. * Ported from tools/save_deliverable.js (lines 56-75). */ /** * @typedef {Object} ValidationResult * @property {boolean} valid * @property {string} [message] * @property {Object} [data] */ /** * Validate JSON structure for queue files * Queue files must have a 'vulnerabilities' array * * @param {string} content - JSON string to validate * @returns {ValidationResult} ValidationResult with valid flag, optional error message, and parsed data */ export function validateQueueJson(content) { try { const parsed = JSON.parse(content); // Queue files must have a 'vulnerabilities' array if (!parsed.vulnerabilities) { return { valid: false, message: `Invalid queue structure: Missing 'vulnerabilities' property. Expected: {"vulnerabilities": [...]}`, }; } if (!Array.isArray(parsed.vulnerabilities)) { return { valid: false, message: `Invalid queue structure: 'vulnerabilities' must be an array. Expected: {"vulnerabilities": [...]}`, }; } return { valid: true, data: parsed, }; } catch (error) { return { valid: false, message: `Invalid JSON: ${error instanceof Error ? error.message : String(error)}`, }; } }