@diegovelasquezweb/a11y-engine 0.1.6 → 0.1.7

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.6",
3
+ "version": "0.1.7",
4
4
  "description": "WCAG 2.2 AA accessibility audit engine — scanner, analyzer, and report builders",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,3 +1,67 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Core types
3
+ // ---------------------------------------------------------------------------
4
+
5
+ export interface Finding {
6
+ id: string;
7
+ rule_id: string;
8
+ title: string;
9
+ severity: string;
10
+ wcag: string;
11
+ wcag_classification: string | null;
12
+ wcag_criterion_id: string | null;
13
+ category: string | null;
14
+ area: string;
15
+ url: string;
16
+ selector: string;
17
+ primary_selector: string;
18
+ impacted_users: string;
19
+ actual: string;
20
+ expected: string;
21
+ primary_failure_mode: string | null;
22
+ relationship_hint: string | null;
23
+ failure_checks: unknown[];
24
+ related_context: unknown[];
25
+ mdn: string | null;
26
+ fix_description: string | null;
27
+ fix_code: string | null;
28
+ fix_code_lang: string | null;
29
+ recommended_fix: string;
30
+ evidence: unknown[];
31
+ total_instances: number | null;
32
+ effort: string | null;
33
+ related_rules: string[];
34
+ screenshot_path: string | null;
35
+ false_positive_risk: string | null;
36
+ guardrails: Record<string, unknown> | null;
37
+ fix_difficulty_notes: string | string[] | null;
38
+ framework_notes: string | null;
39
+ cms_notes: string | null;
40
+ file_search_pattern: string | null;
41
+ ownership_status: string;
42
+ ownership_reason: string | null;
43
+ primary_source_scope: string[];
44
+ search_strategy: string;
45
+ managed_by_library: string | null;
46
+ component_hint: string | null;
47
+ verification_command: string | null;
48
+ verification_command_fallback: string | null;
49
+ check_data: Record<string, unknown> | null;
50
+ source?: string;
51
+ source_rule_id?: string | null;
52
+ pages_affected?: number | null;
53
+ affected_urls?: string[] | null;
54
+ }
55
+
56
+ export interface EnrichedFinding extends Finding {
57
+ ruleId: string;
58
+ sourceRuleId: string | null;
59
+ fixDescription: string | null;
60
+ fixCode: string | null;
61
+ falsePositiveRisk: string | null;
62
+ fixDifficultyNotes: string | string[] | null;
63
+ }
64
+
1
65
  export interface SeverityTotals {
2
66
  Critical: number;
3
67
  Serious: number;
@@ -5,7 +69,7 @@ export interface SeverityTotals {
5
69
  Minor: number;
6
70
  }
7
71
 
8
- export interface ScoreResult {
72
+ export interface ComplianceScore {
9
73
  score: number;
10
74
  label: string;
11
75
  wcagStatus: "Pass" | "Conditional Pass" | "Fail";
@@ -17,33 +81,12 @@ export interface PersonaGroup {
17
81
  icon: string;
18
82
  }
19
83
 
20
- export interface EngineAssets {
21
- intelligence: Record<string, unknown>;
22
- pa11yConfig: Record<string, unknown>;
23
- complianceConfig: Record<string, unknown>;
24
- wcagReference: Record<string, unknown>;
25
- }
26
-
27
- export function getAssets(): EngineAssets;
28
-
29
- export function mapPa11yRuleToCanonical(
30
- ruleId: string,
31
- sourceRuleId?: string | null,
32
- checkData?: Record<string, unknown> | null
33
- ): string;
34
-
35
- export function enrichFindings<T extends Record<string, unknown>>(
36
- findings: T[]
37
- ): T[];
38
-
39
- export function computeScore(totals: SeverityTotals): ScoreResult;
40
-
41
- export function computePersonaGroups(
42
- findings: Record<string, unknown>[]
43
- ): Record<string, PersonaGroup>;
84
+ // ---------------------------------------------------------------------------
85
+ // Report types
86
+ // ---------------------------------------------------------------------------
44
87
 
45
88
  export interface ScanPayload {
46
- findings: Record<string, unknown>[];
89
+ findings: Finding[] | Record<string, unknown>[];
47
90
  metadata?: Record<string, unknown>;
48
91
  }
49
92
 
@@ -52,11 +95,34 @@ export interface ReportOptions {
52
95
  target?: string;
53
96
  }
54
97
 
55
- export function generatePDF(
98
+ export interface PDFReport {
99
+ buffer: Buffer;
100
+ contentType: "application/pdf";
101
+ }
102
+
103
+ export interface ChecklistReport {
104
+ html: string;
105
+ contentType: "text/html";
106
+ }
107
+
108
+ // ---------------------------------------------------------------------------
109
+ // Public API
110
+ // ---------------------------------------------------------------------------
111
+
112
+ export function getEnrichedFindings(findings: Finding[]): EnrichedFinding[];
113
+ export function getEnrichedFindings(findings: Record<string, unknown>[]): EnrichedFinding[];
114
+
115
+ export function getComplianceScore(totals: SeverityTotals): ComplianceScore;
116
+
117
+ export function getPersonaGroups(
118
+ findings: EnrichedFinding[] | Record<string, unknown>[]
119
+ ): Record<string, PersonaGroup>;
120
+
121
+ export function getPDFReport(
56
122
  payload: ScanPayload,
57
123
  options?: ReportOptions
58
- ): Promise<Buffer>;
124
+ ): Promise<PDFReport>;
59
125
 
60
- export function generateChecklist(
126
+ export function getChecklist(
61
127
  options?: Pick<ReportOptions, "baseUrl">
62
- ): Promise<string>;
128
+ ): Promise<ChecklistReport>;
package/scripts/index.mjs CHANGED
@@ -49,7 +49,7 @@ function getWcagReference() {
49
49
  * Returns all engine asset data. Lazy-loaded and cached.
50
50
  * @returns {{ intelligence: object, pa11yConfig: object, complianceConfig: object, wcagReference: object }}
51
51
  */
52
- export function getAssets() {
52
+ function getAssets() {
53
53
  return {
54
54
  intelligence: getIntelligence(),
55
55
  pa11yConfig: getPa11yConfig(),
@@ -82,7 +82,7 @@ function normalizePa11yToken(value) {
82
82
  * @param {object|null} checkData - The check_data object which may contain a `code` field.
83
83
  * @returns {string} The canonical rule ID (e.g., "color-contrast").
84
84
  */
85
- export function mapPa11yRuleToCanonical(ruleId, sourceRuleId = null, checkData = null) {
85
+ function mapPa11yRuleToCanonical(ruleId, sourceRuleId = null, checkData = null) {
86
86
  const equivalenceMap = getPa11yConfig().equivalenceMap || {};
87
87
 
88
88
  const checkCode = checkData && typeof checkData === "object" && typeof checkData.code === "string"
@@ -119,7 +119,7 @@ export function mapPa11yRuleToCanonical(ruleId, sourceRuleId = null, checkData =
119
119
  * @param {object[]} findings - Array of findings with camelCase keys.
120
120
  * @returns {object[]} Enriched findings.
121
121
  */
122
- export function enrichFindings(findings) {
122
+ export function getEnrichedFindings(findings) {
123
123
  const rules = getIntelligence().rules || {};
124
124
 
125
125
  return findings.map((finding) => {
@@ -168,7 +168,7 @@ export function enrichFindings(findings) {
168
168
  * @param {{ Critical: number, Serious: number, Moderate: number, Minor: number }} totals
169
169
  * @returns {{ score: number, label: string, wcagStatus: "Pass" | "Conditional Pass" | "Fail" }}
170
170
  */
171
- export function computeScore(totals) {
171
+ export function getComplianceScore(totals) {
172
172
  const config = getComplianceConfig();
173
173
  const penalties = config.complianceScore.penalties;
174
174
  const thresholds = config.gradeThresholds;
@@ -206,7 +206,7 @@ export function computeScore(totals) {
206
206
  * @param {object[]} findings - Array of findings with ruleId, wcagCriterionId, impactedUsers.
207
207
  * @returns {Record<string, { label: string, count: number, icon: string }>}
208
208
  */
209
- export function computePersonaGroups(findings) {
209
+ export function getPersonaGroups(findings) {
210
210
  const ref = getWcagReference();
211
211
  const personaConfig = ref.personaConfig || {};
212
212
  const personaMapping = ref.personaMapping || {};
@@ -281,7 +281,7 @@ import {
281
281
  * @param {{ baseUrl?: string, target?: string }} [options={}]
282
282
  * @returns {Promise<Buffer>} The PDF as a Node.js Buffer.
283
283
  */
284
- export async function generatePDF(payload, options = {}) {
284
+ export async function getPDFReport(payload, options = {}) {
285
285
  const { chromium } = await import("playwright");
286
286
  const {
287
287
  buildPdfCoverPage,
@@ -334,7 +334,10 @@ ${buildPdfAuditLimitations()}
334
334
  margin: { top: "1cm", right: "1cm", bottom: "1cm", left: "1cm" },
335
335
  displayHeaderFooter: false,
336
336
  });
337
- return Buffer.from(pdfBuffer);
337
+ return {
338
+ buffer: Buffer.from(pdfBuffer),
339
+ contentType: "application/pdf",
340
+ };
338
341
  } finally {
339
342
  await browser.close();
340
343
  }
@@ -346,7 +349,7 @@ ${buildPdfAuditLimitations()}
346
349
  * @param {{ baseUrl?: string }} [options={}]
347
350
  * @returns {Promise<string>} The complete checklist HTML document.
348
351
  */
349
- export async function generateChecklist(options = {}) {
352
+ export async function getChecklist(options = {}) {
350
353
  const { buildManualCheckCard } = await import("./reports/renderers/html.mjs");
351
354
  const { escapeHtml } = await import("./reports/renderers/utils.mjs");
352
355
 
@@ -365,7 +368,7 @@ export async function generateChecklist(options = {}) {
365
368
  // Import the full checklist builder to reuse its buildHtml
366
369
  // The checklist builder module has a main() that auto-runs, so we dynamically
367
370
  // construct the same output using the renderer functions directly.
368
- return `<!doctype html>
371
+ const html = `<!doctype html>
369
372
  <html lang="en">
370
373
  <head>
371
374
  <meta charset="utf-8">
@@ -441,4 +444,9 @@ export async function generateChecklist(options = {}) {
441
444
  <\/script>
442
445
  </body>
443
446
  </html>`;
447
+
448
+ return {
449
+ html,
450
+ contentType: "text/html",
451
+ };
444
452
  }