mirror of
https://github.com/KeygraphHQ/shannon.git
synced 2026-02-12 17:22:50 +00:00
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
/**
|
|
* 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)}`,
|
|
};
|
|
}
|
|
}
|