@greenarmor/ges-core 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fix-assignments/index.d.ts +39 -0
- package/dist/fix-assignments/index.js +146 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/index.d.ts +29 -1
- package/package.json +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { FixAssignment, FixAssignmentStatus, SeverityLevel } from "../types/index.js";
|
|
2
|
+
export declare function loadFixAssignments(projectPath: string): FixAssignment[];
|
|
3
|
+
export declare function saveFixAssignments(projectPath: string, assignments: FixAssignment[]): void;
|
|
4
|
+
export declare function generateAssignmentId(): string;
|
|
5
|
+
export declare function findingKey(opts: {
|
|
6
|
+
ruleId: string;
|
|
7
|
+
file: string;
|
|
8
|
+
line?: number;
|
|
9
|
+
}): string;
|
|
10
|
+
export interface CreateFixAssignmentInput {
|
|
11
|
+
finding_key: string;
|
|
12
|
+
finding_rule_id: string;
|
|
13
|
+
finding_title: string;
|
|
14
|
+
finding_file: string;
|
|
15
|
+
finding_line?: number;
|
|
16
|
+
finding_severity: SeverityLevel;
|
|
17
|
+
finding_control_ids: string[];
|
|
18
|
+
governance_record_id: string;
|
|
19
|
+
governance_system_name: string;
|
|
20
|
+
assignee: string;
|
|
21
|
+
assignee_role: string;
|
|
22
|
+
assigned_by: string;
|
|
23
|
+
notes?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function createFixAssignment(opts: CreateFixAssignmentInput): FixAssignment;
|
|
26
|
+
export declare function addFixAssignment(projectPath: string, assignment: FixAssignment): FixAssignment;
|
|
27
|
+
export declare function updateFixAssignment(projectPath: string, id: string, updates: Partial<FixAssignment>): FixAssignment | null;
|
|
28
|
+
export declare function updateFixAssignmentStatus(projectPath: string, findingKey: string, status: FixAssignmentStatus): FixAssignment | null;
|
|
29
|
+
export declare function findFixAssignment(projectPath: string, findingKey: string): FixAssignment | null;
|
|
30
|
+
export declare function findFixAssignmentById(projectPath: string, id: string): FixAssignment | null;
|
|
31
|
+
export declare function findFixAssignmentsForRecord(projectPath: string, governanceRecordId: string): FixAssignment[];
|
|
32
|
+
export declare function resolveFixAssignment(projectPath: string, findingKey: string, resolution: {
|
|
33
|
+
resolved_by: string;
|
|
34
|
+
resolved_by_role: string;
|
|
35
|
+
method: "auto-fix" | "manual" | "not-applicable";
|
|
36
|
+
resolution_notes: string;
|
|
37
|
+
}): FixAssignment | null;
|
|
38
|
+
export declare function deleteFixAssignment(projectPath: string, id: string): boolean;
|
|
39
|
+
export declare function unassignFix(projectPath: string, findingKey: string): boolean;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
const ASSIGNMENTS_FILE = "fix-assignments.json";
|
|
4
|
+
function assignmentsPath(projectPath) {
|
|
5
|
+
return path.join(projectPath, ".ges", ASSIGNMENTS_FILE);
|
|
6
|
+
}
|
|
7
|
+
export function loadFixAssignments(projectPath) {
|
|
8
|
+
const aPath = assignmentsPath(projectPath);
|
|
9
|
+
try {
|
|
10
|
+
const raw = fs.readFileSync(aPath, "utf-8");
|
|
11
|
+
const data = JSON.parse(raw);
|
|
12
|
+
return Array.isArray(data) ? data : [];
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function saveFixAssignments(projectPath, assignments) {
|
|
19
|
+
const gesDir = path.join(projectPath, ".ges");
|
|
20
|
+
if (!fs.existsSync(gesDir)) {
|
|
21
|
+
fs.mkdirSync(gesDir, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
fs.writeFileSync(assignmentsPath(projectPath), JSON.stringify(assignments, null, 2), "utf-8");
|
|
24
|
+
}
|
|
25
|
+
let assignmentCounter = 0;
|
|
26
|
+
export function generateAssignmentId() {
|
|
27
|
+
assignmentCounter++;
|
|
28
|
+
return `fa-${Date.now()}-${assignmentCounter}`;
|
|
29
|
+
}
|
|
30
|
+
export function findingKey(opts) {
|
|
31
|
+
return `${opts.ruleId}:${opts.file}:${opts.line || 0}`;
|
|
32
|
+
}
|
|
33
|
+
export function createFixAssignment(opts) {
|
|
34
|
+
const now = new Date().toISOString();
|
|
35
|
+
const id = generateAssignmentId();
|
|
36
|
+
return {
|
|
37
|
+
id,
|
|
38
|
+
finding_key: opts.finding_key,
|
|
39
|
+
finding_rule_id: opts.finding_rule_id,
|
|
40
|
+
finding_title: opts.finding_title,
|
|
41
|
+
finding_file: opts.finding_file,
|
|
42
|
+
finding_line: opts.finding_line,
|
|
43
|
+
finding_severity: opts.finding_severity,
|
|
44
|
+
finding_control_ids: opts.finding_control_ids,
|
|
45
|
+
governance_record_id: opts.governance_record_id,
|
|
46
|
+
governance_system_name: opts.governance_system_name,
|
|
47
|
+
assignee: opts.assignee,
|
|
48
|
+
assignee_role: opts.assignee_role,
|
|
49
|
+
assigned_at: now,
|
|
50
|
+
assigned_by: opts.assigned_by,
|
|
51
|
+
status: "assigned",
|
|
52
|
+
notes: opts.notes || "",
|
|
53
|
+
resolution: null,
|
|
54
|
+
created_at: now,
|
|
55
|
+
updated_at: now,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function addFixAssignment(projectPath, assignment) {
|
|
59
|
+
const assignments = loadFixAssignments(projectPath);
|
|
60
|
+
const existingIdx = assignments.findIndex(a => a.finding_key === assignment.finding_key);
|
|
61
|
+
if (existingIdx !== -1) {
|
|
62
|
+
assignments[existingIdx] = assignment;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
assignments.push(assignment);
|
|
66
|
+
}
|
|
67
|
+
saveFixAssignments(projectPath, assignments);
|
|
68
|
+
return assignment;
|
|
69
|
+
}
|
|
70
|
+
export function updateFixAssignment(projectPath, id, updates) {
|
|
71
|
+
const assignments = loadFixAssignments(projectPath);
|
|
72
|
+
const idx = assignments.findIndex(a => a.id === id);
|
|
73
|
+
if (idx === -1)
|
|
74
|
+
return null;
|
|
75
|
+
const now = new Date().toISOString();
|
|
76
|
+
assignments[idx] = {
|
|
77
|
+
...assignments[idx],
|
|
78
|
+
...updates,
|
|
79
|
+
updated_at: now,
|
|
80
|
+
};
|
|
81
|
+
saveFixAssignments(projectPath, assignments);
|
|
82
|
+
return assignments[idx];
|
|
83
|
+
}
|
|
84
|
+
export function updateFixAssignmentStatus(projectPath, findingKey, status) {
|
|
85
|
+
const assignments = loadFixAssignments(projectPath);
|
|
86
|
+
const idx = assignments.findIndex(a => a.finding_key === findingKey);
|
|
87
|
+
if (idx === -1)
|
|
88
|
+
return null;
|
|
89
|
+
const now = new Date().toISOString();
|
|
90
|
+
assignments[idx] = {
|
|
91
|
+
...assignments[idx],
|
|
92
|
+
status,
|
|
93
|
+
updated_at: now,
|
|
94
|
+
};
|
|
95
|
+
saveFixAssignments(projectPath, assignments);
|
|
96
|
+
return assignments[idx];
|
|
97
|
+
}
|
|
98
|
+
export function findFixAssignment(projectPath, findingKey) {
|
|
99
|
+
const assignments = loadFixAssignments(projectPath);
|
|
100
|
+
return assignments.find(a => a.finding_key === findingKey) || null;
|
|
101
|
+
}
|
|
102
|
+
export function findFixAssignmentById(projectPath, id) {
|
|
103
|
+
const assignments = loadFixAssignments(projectPath);
|
|
104
|
+
return assignments.find(a => a.id === id) || null;
|
|
105
|
+
}
|
|
106
|
+
export function findFixAssignmentsForRecord(projectPath, governanceRecordId) {
|
|
107
|
+
const assignments = loadFixAssignments(projectPath);
|
|
108
|
+
return assignments.filter(a => a.governance_record_id === governanceRecordId);
|
|
109
|
+
}
|
|
110
|
+
export function resolveFixAssignment(projectPath, findingKey, resolution) {
|
|
111
|
+
const assignments = loadFixAssignments(projectPath);
|
|
112
|
+
const idx = assignments.findIndex(a => a.finding_key === findingKey);
|
|
113
|
+
if (idx === -1)
|
|
114
|
+
return null;
|
|
115
|
+
const now = new Date().toISOString();
|
|
116
|
+
assignments[idx] = {
|
|
117
|
+
...assignments[idx],
|
|
118
|
+
status: "fixed",
|
|
119
|
+
resolution: {
|
|
120
|
+
resolved_at: now,
|
|
121
|
+
resolved_by: resolution.resolved_by,
|
|
122
|
+
resolved_by_role: resolution.resolved_by_role,
|
|
123
|
+
method: resolution.method,
|
|
124
|
+
resolution_notes: resolution.resolution_notes,
|
|
125
|
+
},
|
|
126
|
+
updated_at: now,
|
|
127
|
+
};
|
|
128
|
+
saveFixAssignments(projectPath, assignments);
|
|
129
|
+
return assignments[idx];
|
|
130
|
+
}
|
|
131
|
+
export function deleteFixAssignment(projectPath, id) {
|
|
132
|
+
const assignments = loadFixAssignments(projectPath);
|
|
133
|
+
const filtered = assignments.filter(a => a.id !== id);
|
|
134
|
+
if (filtered.length === assignments.length)
|
|
135
|
+
return false;
|
|
136
|
+
saveFixAssignments(projectPath, filtered);
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
export function unassignFix(projectPath, findingKey) {
|
|
140
|
+
const assignments = loadFixAssignments(projectPath);
|
|
141
|
+
const filtered = assignments.filter(a => a.finding_key !== findingKey);
|
|
142
|
+
if (filtered.length === assignments.length)
|
|
143
|
+
return false;
|
|
144
|
+
saveFixAssignments(projectPath, filtered);
|
|
145
|
+
return true;
|
|
146
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -193,7 +193,35 @@ export interface FixHistoryEntry {
|
|
|
193
193
|
severity_resolved: SeverityLevel;
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
|
-
export type
|
|
196
|
+
export type FixAssignmentStatus = "assigned" | "in-progress" | "fixed" | "verified" | "rejected";
|
|
197
|
+
export interface FixAssignment {
|
|
198
|
+
id: string;
|
|
199
|
+
finding_key: string;
|
|
200
|
+
finding_rule_id: string;
|
|
201
|
+
finding_title: string;
|
|
202
|
+
finding_file: string;
|
|
203
|
+
finding_line?: number;
|
|
204
|
+
finding_severity: SeverityLevel;
|
|
205
|
+
finding_control_ids: string[];
|
|
206
|
+
governance_record_id: string;
|
|
207
|
+
governance_system_name: string;
|
|
208
|
+
assignee: string;
|
|
209
|
+
assignee_role: string;
|
|
210
|
+
assigned_at: string;
|
|
211
|
+
assigned_by: string;
|
|
212
|
+
status: FixAssignmentStatus;
|
|
213
|
+
notes: string;
|
|
214
|
+
resolution: null | {
|
|
215
|
+
resolved_at: string;
|
|
216
|
+
resolved_by: string;
|
|
217
|
+
resolved_by_role: string;
|
|
218
|
+
method: "auto-fix" | "manual" | "not-applicable";
|
|
219
|
+
resolution_notes: string;
|
|
220
|
+
};
|
|
221
|
+
created_at: string;
|
|
222
|
+
updated_at: string;
|
|
223
|
+
}
|
|
224
|
+
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";
|
|
197
225
|
export type ActivityStatus = "success" | "partial" | "failed" | "info";
|
|
198
226
|
export interface ActivityLogEntry {
|
|
199
227
|
id: string;
|