/home/techb158/cosmic.abdallabala.com/src/integrations/pmClients
Edit: /home/techb158/cosmic.abdallabala.com/src/integrations/pmClients/httpClient.js (2227B)
function ensureFetch(fetchImpl) {
const resolved = fetchImpl || global.fetch;
if (!resolved) throw new Error("Global fetch is not available. Use Node.js 18+ or inject a fetch implementation.");
return resolved;
}
async function fetchJson(url, options = {}, fetchImpl) {
const fetchFn = ensureFetch(fetchImpl);
const response = await fetchFn(url, options);
const text = await response.text();
let body = null;
try { body = text ? JSON.parse(text) : null; } catch (_error) { body = { raw: text }; }
if (!response.ok) {
const message = body && (body.message || body.error || body.error_description) || text || response.statusText;
const error = new Error(`HTTP ${response.status}: ${message}`);
error.status = response.status;
error.body = body;
throw error;
}
return body;
}
function encodeQuery(params) {
const search = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== "") search.set(key, String(value));
});
return search.toString();
}
function buildRiskDescription(risk, mitigations = []) {
const mitigationLines = mitigations.length
? mitigations.map(item => `- ${item.action || item.title || item.id} (${item.status || "Unknown"}, ${item.progress_percent || item.progressPercent || 0}% progress)`).join("\n")
: "- No mitigation action recorded yet";
return [
`COSMIC AI-Risk: ${risk.title}`,
`Dimension: ${risk.dimension}`,
`Lifecycle phase: ${risk.lifecycle_phase || risk.lifecyclePhase || "Not specified"}`,
`Probability: ${risk.probability}`,
`Impact: ${risk.impact}`,
`Detectability: ${risk.detectability}`,
`Status: ${risk.status}`,
`Approval: ${risk.approval_status || risk.approvalStatus || "Pending"}`,
"",
"Mitigations:",
mitigationLines,
"",
"Generated by COSMIC AI-Risk Dashboard."
].join("\n");
}
function jiraDoc(text) {
return {
type: "doc",
version: 1,
content: String(text).split("\n").map(line => ({
type: "paragraph",
content: line ? [{ type: "text", text: line }] : []
}))
};
}
module.exports = {
fetchJson,
encodeQuery,
buildRiskDescription,
jiraDoc
};