diff --git a/public/common/scorecard.js b/public/common/scorecard.js index 51e405f1..30cee964 100644 --- a/public/common/scorecard.js +++ b/public/common/scorecard.js @@ -1,12 +1,56 @@ // Import Third-party Dependencies import { getJSON } from "@nodesecure/vis-network"; +/** + * @typedef {Object} ScorecardCheckDocumentation + * @property {string} short + * @property {string} url + */ + +/** + * @typedef {Object} ScorecardCheck + * @property {string} name + * @property {number} score + * @property {string} reason + * @property {string[] | null} details + * @property {ScorecardCheckDocumentation} documentation + */ + +/** + * @typedef {Object} ScorecardRepo + * @property {string} name + * @property {string} commit + */ + +/** + * @typedef {Object} ScorecardTool + * @property {string} version + * @property {string} commit + */ + +/** + * @typedef {Object} ScorecardData + * @property {string} date + * @property {ScorecardRepo} repo + * @property {ScorecardTool} scorecard + * @property {number} score + * @property {ScorecardCheck[]} checks + */ + /** * @param {!string} repoName + * @param {string} platform + * @returns {Promise} */ export async function fetchScorecardData(repoName, platform = "github.com") { try { - const { data } = (await getJSON(`/scorecard/${repoName}?platform=${platform}`)); + /** @type any responseRaw */ + const responseRaw = (await getJSON(`/scorecard/${repoName}?platform=${platform}`)); + + /** @type {{ data: ScorecardData }} */ + const response = responseRaw; + + const data = response.data; if (!data) { return null; } @@ -20,6 +64,11 @@ export async function fetchScorecardData(repoName, platform = "github.com") { } } +/** + * @param {string} repoName + * @param {string} platform + * @returns {string} + */ export function getScorecardLink( repoName, platform