@greenarmor/ges-core
Advanced tools
| import type { FixAssignment, FixAssignmentStatus, SeverityLevel } from "../types/index.js"; | ||
| export declare function loadFixAssignments(projectPath: string): FixAssignment[]; | ||
| export declare function saveFixAssignments(projectPath: string, assignments: FixAssignment[]): void; | ||
| export declare function generateAssignmentId(): string; | ||
| export declare function findingKey(opts: { | ||
| ruleId: string; | ||
| file: string; | ||
| line?: number; | ||
| }): string; | ||
| export interface CreateFixAssignmentInput { | ||
| finding_key: string; | ||
| finding_rule_id: string; | ||
| finding_title: string; | ||
| finding_file: string; | ||
| finding_line?: number; | ||
| finding_severity: SeverityLevel; | ||
| finding_control_ids: string[]; | ||
| governance_record_id: string; | ||
| governance_system_name: string; | ||
| assignee: string; | ||
| assignee_role: string; | ||
| assigned_by: string; | ||
| notes?: string; | ||
| } | ||
| export declare function createFixAssignment(opts: CreateFixAssignmentInput): FixAssignment; | ||
| export declare function addFixAssignment(projectPath: string, assignment: FixAssignment): FixAssignment; | ||
| export declare function updateFixAssignment(projectPath: string, id: string, updates: Partial<FixAssignment>): FixAssignment | null; | ||
| export declare function updateFixAssignmentStatus(projectPath: string, findingKey: string, status: FixAssignmentStatus): FixAssignment | null; | ||
| export declare function findFixAssignment(projectPath: string, findingKey: string): FixAssignment | null; | ||
| export declare function findFixAssignmentById(projectPath: string, id: string): FixAssignment | null; | ||
| export declare function findFixAssignmentsForRecord(projectPath: string, governanceRecordId: string): FixAssignment[]; | ||
| export declare function resolveFixAssignment(projectPath: string, findingKey: string, resolution: { | ||
| resolved_by: string; | ||
| resolved_by_role: string; | ||
| method: "auto-fix" | "manual" | "not-applicable"; | ||
| resolution_notes: string; | ||
| }): FixAssignment | null; | ||
| export declare function deleteFixAssignment(projectPath: string, id: string): boolean; | ||
| export declare function unassignFix(projectPath: string, findingKey: string): boolean; |
| import * as fs from "node:fs"; | ||
| import * as path from "node:path"; | ||
| const ASSIGNMENTS_FILE = "fix-assignments.json"; | ||
| function assignmentsPath(projectPath) { | ||
| return path.join(projectPath, ".ges", ASSIGNMENTS_FILE); | ||
| } | ||
| export function loadFixAssignments(projectPath) { | ||
| const aPath = assignmentsPath(projectPath); | ||
| try { | ||
| const raw = fs.readFileSync(aPath, "utf-8"); | ||
| const data = JSON.parse(raw); | ||
| return Array.isArray(data) ? data : []; | ||
| } | ||
| catch { | ||
| return []; | ||
| } | ||
| } | ||
| export function saveFixAssignments(projectPath, assignments) { | ||
| const gesDir = path.join(projectPath, ".ges"); | ||
| if (!fs.existsSync(gesDir)) { | ||
| fs.mkdirSync(gesDir, { recursive: true }); | ||
| } | ||
| fs.writeFileSync(assignmentsPath(projectPath), JSON.stringify(assignments, null, 2), "utf-8"); | ||
| } | ||
| let assignmentCounter = 0; | ||
| export function generateAssignmentId() { | ||
| assignmentCounter++; | ||
| return `fa-${Date.now()}-${assignmentCounter}`; | ||
| } | ||
| export function findingKey(opts) { | ||
| return `${opts.ruleId}:${opts.file}:${opts.line || 0}`; | ||
| } | ||
| export function createFixAssignment(opts) { | ||
| const now = new Date().toISOString(); | ||
| const id = generateAssignmentId(); | ||
| return { | ||
| id, | ||
| finding_key: opts.finding_key, | ||
| finding_rule_id: opts.finding_rule_id, | ||
| finding_title: opts.finding_title, | ||
| finding_file: opts.finding_file, | ||
| finding_line: opts.finding_line, | ||
| finding_severity: opts.finding_severity, | ||
| finding_control_ids: opts.finding_control_ids, | ||
| governance_record_id: opts.governance_record_id, | ||
| governance_system_name: opts.governance_system_name, | ||
| assignee: opts.assignee, | ||
| assignee_role: opts.assignee_role, | ||
| assigned_at: now, | ||
| assigned_by: opts.assigned_by, | ||
| status: "assigned", | ||
| notes: opts.notes || "", | ||
| resolution: null, | ||
| created_at: now, | ||
| updated_at: now, | ||
| }; | ||
| } | ||
| export function addFixAssignment(projectPath, assignment) { | ||
| const assignments = loadFixAssignments(projectPath); | ||
| const existingIdx = assignments.findIndex(a => a.finding_key === assignment.finding_key); | ||
| if (existingIdx !== -1) { | ||
| assignments[existingIdx] = assignment; | ||
| } | ||
| else { | ||
| assignments.push(assignment); | ||
| } | ||
| saveFixAssignments(projectPath, assignments); | ||
| return assignment; | ||
| } | ||
| export function updateFixAssignment(projectPath, id, updates) { | ||
| const assignments = loadFixAssignments(projectPath); | ||
| const idx = assignments.findIndex(a => a.id === id); | ||
| if (idx === -1) | ||
| return null; | ||
| const now = new Date().toISOString(); | ||
| assignments[idx] = { | ||
| ...assignments[idx], | ||
| ...updates, | ||
| updated_at: now, | ||
| }; | ||
| saveFixAssignments(projectPath, assignments); | ||
| return assignments[idx]; | ||
| } | ||
| export function updateFixAssignmentStatus(projectPath, findingKey, status) { | ||
| const assignments = loadFixAssignments(projectPath); | ||
| const idx = assignments.findIndex(a => a.finding_key === findingKey); | ||
| if (idx === -1) | ||
| return null; | ||
| const now = new Date().toISOString(); | ||
| assignments[idx] = { | ||
| ...assignments[idx], | ||
| status, | ||
| updated_at: now, | ||
| }; | ||
| saveFixAssignments(projectPath, assignments); | ||
| return assignments[idx]; | ||
| } | ||
| export function findFixAssignment(projectPath, findingKey) { | ||
| const assignments = loadFixAssignments(projectPath); | ||
| return assignments.find(a => a.finding_key === findingKey) || null; | ||
| } | ||
| export function findFixAssignmentById(projectPath, id) { | ||
| const assignments = loadFixAssignments(projectPath); | ||
| return assignments.find(a => a.id === id) || null; | ||
| } | ||
| export function findFixAssignmentsForRecord(projectPath, governanceRecordId) { | ||
| const assignments = loadFixAssignments(projectPath); | ||
| return assignments.filter(a => a.governance_record_id === governanceRecordId); | ||
| } | ||
| export function resolveFixAssignment(projectPath, findingKey, resolution) { | ||
| const assignments = loadFixAssignments(projectPath); | ||
| const idx = assignments.findIndex(a => a.finding_key === findingKey); | ||
| if (idx === -1) | ||
| return null; | ||
| const now = new Date().toISOString(); | ||
| assignments[idx] = { | ||
| ...assignments[idx], | ||
| status: "fixed", | ||
| resolution: { | ||
| resolved_at: now, | ||
| resolved_by: resolution.resolved_by, | ||
| resolved_by_role: resolution.resolved_by_role, | ||
| method: resolution.method, | ||
| resolution_notes: resolution.resolution_notes, | ||
| }, | ||
| updated_at: now, | ||
| }; | ||
| saveFixAssignments(projectPath, assignments); | ||
| return assignments[idx]; | ||
| } | ||
| export function deleteFixAssignment(projectPath, id) { | ||
| const assignments = loadFixAssignments(projectPath); | ||
| const filtered = assignments.filter(a => a.id !== id); | ||
| if (filtered.length === assignments.length) | ||
| return false; | ||
| saveFixAssignments(projectPath, filtered); | ||
| return true; | ||
| } | ||
| export function unassignFix(projectPath, findingKey) { | ||
| const assignments = loadFixAssignments(projectPath); | ||
| const filtered = assignments.filter(a => a.finding_key !== findingKey); | ||
| if (filtered.length === assignments.length) | ||
| return false; | ||
| saveFixAssignments(projectPath, filtered); | ||
| return true; | ||
| } |
+1
-0
@@ -9,1 +9,2 @@ export * from "./types/index.js"; | ||
| export * from "./governance/index.js"; | ||
| export * from "./fix-assignments/index.js"; |
+1
-0
@@ -9,1 +9,2 @@ export * from "./types/index.js"; | ||
| export * from "./governance/index.js"; | ||
| export * from "./fix-assignments/index.js"; |
@@ -196,3 +196,31 @@ export type ProjectType = "saas" | "ai-application" | "mcp-server" | "blockchain" | "wallet" | "government-system" | "healthcare-system" | "event-platform" | "photo-storage-platform" | "vulnerability-scanner" | "generic-web-application" | "api-backend" | "mobile-application"; | ||
| } | ||
| export type ActivityAction = "init" | "audit" | "fix" | "policy_install" | "policy_remove" | "control_override" | "implement_control" | "score" | "scan" | "validate" | "generate" | "hooks_install" | "hooks_uninstall" | "dashboard_start" | "badge_generate"; | ||
| export type FixAssignmentStatus = "assigned" | "in-progress" | "fixed" | "verified" | "rejected"; | ||
| export interface FixAssignment { | ||
| id: string; | ||
| finding_key: string; | ||
| finding_rule_id: string; | ||
| finding_title: string; | ||
| finding_file: string; | ||
| finding_line?: number; | ||
| finding_severity: SeverityLevel; | ||
| finding_control_ids: string[]; | ||
| governance_record_id: string; | ||
| governance_system_name: string; | ||
| assignee: string; | ||
| assignee_role: string; | ||
| assigned_at: string; | ||
| assigned_by: string; | ||
| status: FixAssignmentStatus; | ||
| notes: string; | ||
| resolution: null | { | ||
| resolved_at: string; | ||
| resolved_by: string; | ||
| resolved_by_role: string; | ||
| method: "auto-fix" | "manual" | "not-applicable"; | ||
| resolution_notes: string; | ||
| }; | ||
| created_at: string; | ||
| updated_at: string; | ||
| } | ||
| export type ActivityAction = "init" | "audit" | "fix" | "policy_install" | "policy_remove" | "control_override" | "implement_control" | "score" | "scan" | "validate" | "generate" | "hooks_install" | "hooks_uninstall" | "dashboard_start" | "badge_generate" | "fix_assign" | "fix_resolve"; | ||
| export type ActivityStatus = "success" | "partial" | "failed" | "info"; | ||
@@ -199,0 +227,0 @@ export interface ActivityLogEntry { |
+1
-1
@@ -27,3 +27,3 @@ { | ||
| "types": "./dist/index.d.ts", | ||
| "version": "1.4.3", | ||
| "version": "1.5.0", | ||
| "scripts": { | ||
@@ -30,0 +30,0 @@ "build": "tsc", |
90028
10.15%23
9.52%2219
10.73%