@diegovelasquezweb/a11y-engine 0.1.7 → 0.1.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diegovelasquezweb/a11y-engine",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "WCAG 2.2 AA accessibility audit engine — scanner, analyzer, and report builders",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -58,8 +58,12 @@ export interface EnrichedFinding extends Finding {
58
58
  sourceRuleId: string | null;
59
59
  fixDescription: string | null;
60
60
  fixCode: string | null;
61
+ fixCodeLang: string | null;
61
62
  falsePositiveRisk: string | null;
62
63
  fixDifficultyNotes: string | string[] | null;
64
+ screenshotPath: string | null;
65
+ wcagCriterionId: string | null;
66
+ impactedUsers: string | null;
63
67
  }
64
68
 
65
69
  export interface SeverityTotals {
@@ -69,18 +73,20 @@ export interface SeverityTotals {
69
73
  Minor: number;
70
74
  }
71
75
 
72
- export interface ComplianceScore {
73
- score: number;
74
- label: string;
75
- wcagStatus: "Pass" | "Conditional Pass" | "Fail";
76
- }
77
-
78
76
  export interface PersonaGroup {
79
77
  label: string;
80
78
  count: number;
81
79
  icon: string;
82
80
  }
83
81
 
82
+ export interface AuditSummary {
83
+ totals: SeverityTotals;
84
+ score: number;
85
+ label: string;
86
+ wcagStatus: "Pass" | "Conditional Pass" | "Fail";
87
+ personaGroups: Record<string, PersonaGroup>;
88
+ }
89
+
84
90
  // ---------------------------------------------------------------------------
85
91
  // Report types
86
92
  // ---------------------------------------------------------------------------
@@ -112,11 +118,7 @@ export interface ChecklistReport {
112
118
  export function getEnrichedFindings(findings: Finding[]): EnrichedFinding[];
113
119
  export function getEnrichedFindings(findings: Record<string, unknown>[]): EnrichedFinding[];
114
120
 
115
- export function getComplianceScore(totals: SeverityTotals): ComplianceScore;
116
-
117
- export function getPersonaGroups(
118
- findings: EnrichedFinding[] | Record<string, unknown>[]
119
- ): Record<string, PersonaGroup>;
121
+ export function getAuditSummary(findings: EnrichedFinding[] | Record<string, unknown>[]): AuditSummary;
120
122
 
121
123
  export function getPDFReport(
122
124
  payload: ScanPayload,
package/scripts/index.mjs CHANGED
@@ -129,15 +129,24 @@ export function getEnrichedFindings(findings) {
129
129
  finding.checkData || finding.check_data || null,
130
130
  );
131
131
 
132
+ // Always create camelCase aliases from snake_case fields
132
133
  const normalized = {
133
134
  ...finding,
134
135
  ruleId: canonical,
135
136
  rule_id: canonical,
136
137
  sourceRuleId: finding.sourceRuleId || finding.source_rule_id || finding.ruleId || finding.rule_id || null,
138
+ fixDescription: finding.fixDescription ?? finding.fix_description ?? null,
139
+ fixCode: finding.fixCode ?? finding.fix_code ?? null,
140
+ fixCodeLang: finding.fixCodeLang ?? finding.fix_code_lang ?? null,
141
+ falsePositiveRisk: finding.falsePositiveRisk ?? finding.false_positive_risk ?? null,
142
+ fixDifficultyNotes: finding.fixDifficultyNotes ?? finding.fix_difficulty_notes ?? null,
143
+ screenshotPath: finding.screenshotPath ?? finding.screenshot_path ?? null,
144
+ wcagCriterionId: finding.wcagCriterionId ?? finding.wcag_criterion_id ?? null,
145
+ impactedUsers: finding.impactedUsers ?? finding.impacted_users ?? null,
137
146
  };
138
147
 
139
- if (normalized.fixDescription || normalized.fix_description ||
140
- normalized.fixCode || normalized.fix_code) {
148
+ // If fix data already exists, no need to look up intelligence
149
+ if (normalized.fixDescription || normalized.fixCode) {
141
150
  return normalized;
142
151
  }
143
152
 
@@ -148,27 +157,22 @@ export function getEnrichedFindings(findings) {
148
157
  ...normalized,
149
158
  category: normalized.category ?? info.category ?? null,
150
159
  fixDescription: info.fix?.description ?? null,
151
- fix_description: info.fix?.description ?? null,
160
+ fix_description: info.fix?.description ?? normalized.fix_description ?? null,
152
161
  fixCode: info.fix?.code ?? null,
153
- fix_code: info.fix?.code ?? null,
154
- falsePositiveRisk: normalized.falsePositiveRisk ?? normalized.false_positive_risk ?? info.false_positive_risk ?? null,
162
+ fix_code: info.fix?.code ?? normalized.fix_code ?? null,
163
+ falsePositiveRisk: normalized.falsePositiveRisk ?? info.false_positive_risk ?? null,
155
164
  false_positive_risk: normalized.false_positive_risk ?? info.false_positive_risk ?? null,
156
- fixDifficultyNotes: normalized.fixDifficultyNotes ?? normalized.fix_difficulty_notes ?? info.fix_difficulty_notes ?? null,
165
+ fixDifficultyNotes: normalized.fixDifficultyNotes ?? info.fix_difficulty_notes ?? null,
157
166
  fix_difficulty_notes: normalized.fix_difficulty_notes ?? info.fix_difficulty_notes ?? null,
158
167
  };
159
168
  });
160
169
  }
161
170
 
162
171
  // ---------------------------------------------------------------------------
163
- // Score computation
172
+ // Score computation (internal)
164
173
  // ---------------------------------------------------------------------------
165
174
 
166
- /**
167
- * Computes compliance score, grade label, and WCAG pass/fail status.
168
- * @param {{ Critical: number, Serious: number, Moderate: number, Minor: number }} totals
169
- * @returns {{ score: number, label: string, wcagStatus: "Pass" | "Conditional Pass" | "Fail" }}
170
- */
171
- export function getComplianceScore(totals) {
175
+ function getComplianceScore(totals) {
172
176
  const config = getComplianceConfig();
173
177
  const penalties = config.complianceScore.penalties;
174
178
  const thresholds = config.gradeThresholds;
@@ -198,15 +202,10 @@ export function getComplianceScore(totals) {
198
202
  }
199
203
 
200
204
  // ---------------------------------------------------------------------------
201
- // Persona grouping
205
+ // Persona grouping (internal)
202
206
  // ---------------------------------------------------------------------------
203
207
 
204
- /**
205
- * Groups findings by accessibility persona (screen reader, keyboard, cognitive, etc.).
206
- * @param {object[]} findings - Array of findings with ruleId, wcagCriterionId, impactedUsers.
207
- * @returns {Record<string, { label: string, count: number, icon: string }>}
208
- */
209
- export function getPersonaGroups(findings) {
208
+ function getPersonaGroups(findings) {
210
209
  const ref = getWcagReference();
211
210
  const personaConfig = ref.personaConfig || {};
212
211
  const personaMapping = ref.personaMapping || {};
@@ -261,6 +260,29 @@ export function getPersonaGroups(findings) {
261
260
  return groups;
262
261
  }
263
262
 
263
+ // ---------------------------------------------------------------------------
264
+ // Audit summary
265
+ // ---------------------------------------------------------------------------
266
+
267
+ /**
268
+ * Computes a complete audit summary from enriched findings: severity totals,
269
+ * compliance score, grade label, WCAG status, and persona impact groups.
270
+ * @param {object[]} findings - Array of enriched findings.
271
+ * @returns {{ totals, score, label, wcagStatus, personaGroups }}
272
+ */
273
+ export function getAuditSummary(findings) {
274
+ const totals = { Critical: 0, Serious: 0, Moderate: 0, Minor: 0 };
275
+ for (const f of findings) {
276
+ const severity = f.severity || f.Severity || "";
277
+ if (severity in totals) totals[severity] += 1;
278
+ }
279
+
280
+ const { score, label, wcagStatus } = getComplianceScore(totals);
281
+ const personaGroups = getPersonaGroups(findings);
282
+
283
+ return { totals, score, label, wcagStatus, personaGroups };
284
+ }
285
+
264
286
  // ---------------------------------------------------------------------------
265
287
  // Report generation
266
288
  // ---------------------------------------------------------------------------