@cclabsnz/sf-audit 1.0.1 → 1.1.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.
Files changed (149) hide show
  1. package/README.md +75 -0
  2. package/lib/api/ToolingClientImpl.js +5 -2
  3. package/lib/chains/AttackChain.d.ts +20 -0
  4. package/lib/chains/AttackChain.js +2 -0
  5. package/lib/chains/Capability.d.ts +7 -0
  6. package/lib/chains/Capability.js +11 -0
  7. package/lib/chains/CapabilityRegistry.d.ts +18 -0
  8. package/lib/chains/CapabilityRegistry.js +53 -0
  9. package/lib/chains/ChainEngine.d.ts +13 -0
  10. package/lib/chains/ChainEngine.js +137 -0
  11. package/lib/chains/namedChains.d.ts +14 -0
  12. package/lib/chains/namedChains.js +99 -0
  13. package/lib/checks/CheckEngine.js +33 -5
  14. package/lib/checks/impl/AnonymousApexAuditCheck.d.ts +10 -0
  15. package/lib/checks/impl/AnonymousApexAuditCheck.js +106 -0
  16. package/lib/checks/impl/ApexCrudFLSCheck.d.ts +11 -0
  17. package/lib/checks/impl/ApexCrudFLSCheck.js +98 -0
  18. package/lib/checks/impl/ApexLoggingCheck.d.ts +11 -0
  19. package/lib/checks/impl/ApexLoggingCheck.js +124 -0
  20. package/lib/checks/impl/ApexRestEndpointCheck.d.ts +11 -0
  21. package/lib/checks/impl/ApexRestEndpointCheck.js +94 -0
  22. package/lib/checks/impl/ApexSharingCheck.js +29 -0
  23. package/lib/checks/impl/ApiClientPermissionCheck.d.ts +10 -0
  24. package/lib/checks/impl/ApiClientPermissionCheck.js +59 -0
  25. package/lib/checks/impl/AuditTrailCheck.js +29 -0
  26. package/lib/checks/impl/CertificateExpiryCheck.d.ts +10 -0
  27. package/lib/checks/impl/CertificateExpiryCheck.js +123 -0
  28. package/lib/checks/impl/CodeSecurityCheck.d.ts +2 -1
  29. package/lib/checks/impl/CodeSecurityCheck.js +46 -6
  30. package/lib/checks/impl/ConnectedAppInactivityCheck.d.ts +11 -0
  31. package/lib/checks/impl/ConnectedAppInactivityCheck.js +86 -0
  32. package/lib/checks/impl/ConnectedAppScopeCheck.d.ts +10 -0
  33. package/lib/checks/impl/ConnectedAppScopeCheck.js +125 -0
  34. package/lib/checks/impl/ConnectedAppsCheck.d.ts +1 -0
  35. package/lib/checks/impl/ConnectedAppsCheck.js +37 -2
  36. package/lib/checks/impl/ContentLinksCheck.d.ts +10 -0
  37. package/lib/checks/impl/ContentLinksCheck.js +115 -0
  38. package/lib/checks/impl/CorsAllowlistCheck.d.ts +10 -0
  39. package/lib/checks/impl/CorsAllowlistCheck.js +80 -0
  40. package/lib/checks/impl/CspTrustedSitesCheck.d.ts +10 -0
  41. package/lib/checks/impl/CspTrustedSitesCheck.js +55 -0
  42. package/lib/checks/impl/CustomLabelsCredentialCheck.d.ts +10 -0
  43. package/lib/checks/impl/CustomLabelsCredentialCheck.js +97 -0
  44. package/lib/checks/impl/DataClassificationCheck.d.ts +10 -0
  45. package/lib/checks/impl/DataClassificationCheck.js +112 -0
  46. package/lib/checks/impl/DebugLogAccessCheck.d.ts +10 -0
  47. package/lib/checks/impl/DebugLogAccessCheck.js +81 -0
  48. package/lib/checks/impl/DeploymentIdentityCheck.d.ts +11 -0
  49. package/lib/checks/impl/DeploymentIdentityCheck.js +144 -0
  50. package/lib/checks/impl/EnhancedDomainsCheck.d.ts +10 -0
  51. package/lib/checks/impl/EnhancedDomainsCheck.js +84 -0
  52. package/lib/checks/impl/EscalationPermsCheck.d.ts +10 -0
  53. package/lib/checks/impl/EscalationPermsCheck.js +77 -0
  54. package/lib/checks/impl/EventMonitoringCheck.d.ts +11 -0
  55. package/lib/checks/impl/EventMonitoringCheck.js +84 -0
  56. package/lib/checks/impl/ExperienceCloudSiteCheck.d.ts +10 -0
  57. package/lib/checks/impl/ExperienceCloudSiteCheck.js +91 -0
  58. package/lib/checks/impl/FailedLoginCheck.d.ts +10 -0
  59. package/lib/checks/impl/FailedLoginCheck.js +122 -0
  60. package/lib/checks/impl/FieldHistoryTrackingCheck.d.ts +10 -0
  61. package/lib/checks/impl/FieldHistoryTrackingCheck.js +70 -0
  62. package/lib/checks/impl/FieldLevelSecurityCheck.js +28 -18
  63. package/lib/checks/impl/GuestExecutableApexCheck.d.ts +11 -0
  64. package/lib/checks/impl/GuestExecutableApexCheck.js +93 -0
  65. package/lib/checks/impl/GuestUserAccessCheck.js +74 -66
  66. package/lib/checks/impl/HardcodedCredentialsCheck.js +2 -2
  67. package/lib/checks/impl/HighAssuranceSessionCheck.d.ts +10 -0
  68. package/lib/checks/impl/HighAssuranceSessionCheck.js +103 -0
  69. package/lib/checks/impl/InactiveUsersCheck.js +38 -19
  70. package/lib/checks/impl/InstalledPackagesCheck.d.ts +10 -0
  71. package/lib/checks/impl/InstalledPackagesCheck.js +94 -0
  72. package/lib/checks/impl/IntegrationUsersCheck.d.ts +10 -0
  73. package/lib/checks/impl/IntegrationUsersCheck.js +108 -0
  74. package/lib/checks/impl/InternalUserMfaCheck.d.ts +10 -0
  75. package/lib/checks/impl/InternalUserMfaCheck.js +81 -0
  76. package/lib/checks/impl/IpRestrictionsCheck.js +86 -23
  77. package/lib/checks/impl/LegacyApiVersionCheck.d.ts +10 -0
  78. package/lib/checks/impl/LegacyApiVersionCheck.js +91 -0
  79. package/lib/checks/impl/MfaEnforcementCheck.d.ts +10 -0
  80. package/lib/checks/impl/MfaEnforcementCheck.js +76 -0
  81. package/lib/checks/impl/MfaMethodStrengthCheck.d.ts +11 -0
  82. package/lib/checks/impl/MfaMethodStrengthCheck.js +116 -0
  83. package/lib/checks/impl/MfaRegistrationCheck.d.ts +11 -0
  84. package/lib/checks/impl/MfaRegistrationCheck.js +95 -0
  85. package/lib/checks/impl/MyDomainLoginPolicyCheck.d.ts +10 -0
  86. package/lib/checks/impl/MyDomainLoginPolicyCheck.js +105 -0
  87. package/lib/checks/impl/NamedCredentialsCheck.js +37 -2
  88. package/lib/checks/impl/PermissionsCheck.js +67 -14
  89. package/lib/checks/impl/PublicGroupSharingCheck.js +20 -9
  90. package/lib/checks/impl/ReleaseUpdatesCheck.d.ts +10 -0
  91. package/lib/checks/impl/ReleaseUpdatesCheck.js +106 -0
  92. package/lib/checks/impl/ReportFolderAccessCheck.d.ts +10 -0
  93. package/lib/checks/impl/ReportFolderAccessCheck.js +54 -0
  94. package/lib/checks/impl/ScheduledApexCheck.d.ts +1 -0
  95. package/lib/checks/impl/ScheduledApexCheck.js +3 -0
  96. package/lib/checks/impl/SharingModelCheck.d.ts +1 -1
  97. package/lib/checks/impl/SharingModelCheck.js +103 -32
  98. package/lib/checks/impl/SiemIntegrationCheck.d.ts +11 -0
  99. package/lib/checks/impl/SiemIntegrationCheck.js +102 -0
  100. package/lib/checks/impl/SsoEnforcementCheck.d.ts +10 -0
  101. package/lib/checks/impl/SsoEnforcementCheck.js +90 -0
  102. package/lib/checks/impl/StandardProfilesCheck.d.ts +10 -0
  103. package/lib/checks/impl/StandardProfilesCheck.js +68 -0
  104. package/lib/checks/impl/TransactionSecurityPolicyCheck.d.ts +10 -0
  105. package/lib/checks/impl/TransactionSecurityPolicyCheck.js +62 -0
  106. package/lib/checks/impl/TrustedIPRangesCheck.d.ts +10 -0
  107. package/lib/checks/impl/TrustedIPRangesCheck.js +106 -0
  108. package/lib/checks/impl/UsersAndAdminsCheck.js +50 -20
  109. package/lib/checks/impl/VisualforceXssCheck.d.ts +11 -0
  110. package/lib/checks/impl/VisualforceXssCheck.js +150 -0
  111. package/lib/checks/registry.js +97 -12
  112. package/lib/commands/audit/diff.d.ts +17 -0
  113. package/lib/commands/audit/diff.js +76 -0
  114. package/lib/commands/audit/history.d.ts +15 -0
  115. package/lib/commands/audit/history.js +59 -0
  116. package/lib/commands/audit/security.js +6 -6
  117. package/lib/context/AuditCache.d.ts +20 -0
  118. package/lib/context/AuditContext.d.ts +0 -2
  119. package/lib/findings/AuditResult.d.ts +3 -0
  120. package/lib/findings/ComplianceMapping.d.ts +3 -0
  121. package/lib/findings/ComplianceMapping.js +75 -0
  122. package/lib/findings/Finding.d.ts +20 -0
  123. package/lib/findings/loadScoringConfig.js +9 -2
  124. package/lib/findings/scoring.d.ts +2 -1
  125. package/lib/findings/scoring.js +20 -7
  126. package/lib/history/AuditDiff.d.ts +26 -0
  127. package/lib/history/AuditDiff.js +2 -0
  128. package/lib/history/DiffEngine.d.ts +4 -0
  129. package/lib/history/DiffEngine.js +61 -0
  130. package/lib/history/HistoryStore.d.ts +11 -0
  131. package/lib/history/HistoryStore.js +56 -0
  132. package/lib/history/metricMeta.d.ts +9 -0
  133. package/lib/history/metricMeta.js +28 -0
  134. package/lib/index.d.ts +7 -1
  135. package/lib/index.js +2 -1
  136. package/lib/lib/wire.d.ts +1 -2
  137. package/lib/lib/wire.js +1 -2
  138. package/lib/renderers/DiffHtmlRenderer.d.ts +8 -0
  139. package/lib/renderers/DiffHtmlRenderer.js +164 -0
  140. package/lib/renderers/DiffJsonRenderer.d.ts +8 -0
  141. package/lib/renderers/DiffJsonRenderer.js +8 -0
  142. package/lib/renderers/DiffRenderer.d.ts +7 -0
  143. package/lib/renderers/DiffRenderer.js +2 -0
  144. package/lib/renderers/HistoryRenderer.d.ts +6 -0
  145. package/lib/renderers/HistoryRenderer.js +140 -0
  146. package/lib/renderers/HtmlRenderer.d.ts +1 -0
  147. package/lib/renderers/HtmlRenderer.js +354 -54
  148. package/lib/renderers/MarkdownRenderer.js +34 -1
  149. package/package.json +3 -3
@@ -0,0 +1,164 @@
1
+ function esc(str) {
2
+ return str
3
+ .replace(/&/g, '&')
4
+ .replace(/</g, '&lt;')
5
+ .replace(/>/g, '&gt;')
6
+ .replace(/"/g, '&quot;');
7
+ }
8
+ function fmtDate(d) {
9
+ return d.toISOString().replace('T', ' ').substring(0, 16);
10
+ }
11
+ const RISK_COLORS = {
12
+ CRITICAL: '#dc2626', HIGH: '#ea580c', MEDIUM: '#d97706', LOW: '#2563eb', INFO: '#64748b',
13
+ };
14
+ const CHANGE_LABELS = {
15
+ 'new': 'New', 'resolved': 'Resolved', 'severity-changed': 'Severity Changed', 'detail-changed': 'Detail Changed',
16
+ };
17
+ function renderFindingCard(change) {
18
+ const f = change.finding;
19
+ const typeColor = change.type === 'new' ? '#dc2626' : change.type === 'resolved' ? '#22c55e' : '#d97706';
20
+ const prevBadge = change.previous
21
+ ? `<span class="risk-badge" style="background:${RISK_COLORS[change.previous.riskLevel] ?? '#64748b'}">${esc(change.previous.riskLevel)}</span> → `
22
+ : '';
23
+ return `
24
+ <div class="finding-card" style="border-left-color:${typeColor}">
25
+ <div class="finding-header">
26
+ <span class="change-badge" style="background:${typeColor}">${CHANGE_LABELS[change.type] ?? change.type}</span>
27
+ ${prevBadge}<span class="risk-badge" style="background:${RISK_COLORS[f.riskLevel] ?? '#64748b'}">${esc(f.riskLevel)}</span>
28
+ <span class="finding-title">${esc(f.title)}</span>
29
+ <span class="finding-category">${esc(f.category)}</span>
30
+ </div>
31
+ ${change.type === 'detail-changed' && change.previous ? `
32
+ <div class="detail-diff">
33
+ <div class="diff-before"><strong>Before:</strong> ${esc(change.previous.detail)}</div>
34
+ <div class="diff-after"><strong>After:</strong> ${esc(f.detail)}</div>
35
+ </div>` : ''}
36
+ </div>`;
37
+ }
38
+ export class DiffHtmlRenderer {
39
+ format = 'html';
40
+ fileExtension = '.html';
41
+ render(diff) {
42
+ const { baseline, current } = diff;
43
+ const scoreDeltaStr = diff.scoreDelta >= 0 ? `+${diff.scoreDelta}` : `${diff.scoreDelta}`;
44
+ const scoreDeltaColor = diff.scoreDelta > 0 ? '#22c55e' : diff.scoreDelta < 0 ? '#dc2626' : '#8b949e';
45
+ const changeCounts = {
46
+ new: diff.findingChanges.filter((c) => c.type === 'new').length,
47
+ resolved: diff.findingChanges.filter((c) => c.type === 'resolved').length,
48
+ 'severity-changed': diff.findingChanges.filter((c) => c.type === 'severity-changed').length,
49
+ 'detail-changed': diff.findingChanges.filter((c) => c.type === 'detail-changed').length,
50
+ };
51
+ const sectionOrder = ['new', 'resolved', 'severity-changed', 'detail-changed', 'unchanged'];
52
+ const sections = sectionOrder.map((type) => {
53
+ const changes = diff.findingChanges.filter((c) => c.type === type);
54
+ if (changes.length === 0)
55
+ return '';
56
+ const sectionClass = type === 'unchanged' ? ' class="unchanged-section"' : '';
57
+ return `
58
+ <section${sectionClass}>
59
+ <h2>${CHANGE_LABELS[type] ?? type} (${changes.length})</h2>
60
+ ${changes.map(renderFindingCard).join('')}
61
+ </section>`;
62
+ }).join('');
63
+ const metricRows = diff.metricDeltas.map((d) => {
64
+ const color = d.direction === 'improved' ? '#22c55e' : d.direction === 'degraded' ? '#dc2626' : '#8b949e';
65
+ const arrow = d.delta > 0 ? '▲' : '▼';
66
+ const deltaStr = d.delta > 0 ? `+${d.delta}` : `${d.delta}`;
67
+ return `<tr>
68
+ <td>${esc(d.label)}</td>
69
+ <td style="text-align:right">${d.before}</td>
70
+ <td style="text-align:right">${d.after}</td>
71
+ <td style="text-align:right;color:${color};font-weight:700">${arrow} ${deltaStr}</td>
72
+ </tr>`;
73
+ }).join('');
74
+ const metricsSection = diff.metricDeltas.length > 0 ? `
75
+ <section>
76
+ <h2>Metric Changes</h2>
77
+ <table class="metric-table">
78
+ <thead><tr><th>Metric</th><th>Before</th><th>After</th><th>Change</th></tr></thead>
79
+ <tbody>${metricRows}</tbody>
80
+ </table>
81
+ </section>` : '';
82
+ return `<!DOCTYPE html>
83
+ <html lang="en">
84
+ <head>
85
+ <meta charset="UTF-8">
86
+ <meta name="viewport" content="width=device-width,initial-scale=1">
87
+ <title>SF Audit Diff — ${esc(baseline.orgName)}</title>
88
+ <style>
89
+ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
90
+ body { font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; background: #0d1117; color: #c9d1d9; max-width: 1000px; margin: 2rem auto; padding: 0 1.25rem 4rem; line-height: 1.6; }
91
+ h1 { color: #f0f6fc; font-size: 1.5rem; font-weight: 700; margin-bottom: 0.4rem; }
92
+ h2 { color: #e6edf3; font-size: 1.1rem; font-weight: 700; margin: 1.5rem 0 0.75rem; }
93
+ .meta { font-size: 0.8rem; color: #8b949e; display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; margin-bottom: 1.5rem; }
94
+ .scorecard { background: #161b22; border: 1px solid #30363d; border-radius: 12px; padding: 1.25rem 2rem; display: flex; gap: 2rem; align-items: center; flex-wrap: wrap; margin-bottom: 1.5rem; }
95
+ .score-delta { font-size: 2.5rem; font-weight: 800; color: ${scoreDeltaColor}; line-height: 1; }
96
+ .grade-delta { font-size: 1.2rem; font-weight: 700; color: #c9d1d9; }
97
+ .summary-counts { display: flex; gap: 1rem; flex-wrap: wrap; }
98
+ .count-badge { background: #1c2128; border: 1px solid #30363d; border-radius: 8px; padding: 0.5rem 1rem; text-align: center; }
99
+ .count-badge .num { font-size: 1.5rem; font-weight: 800; display: block; }
100
+ .count-badge .lbl { font-size: 0.75rem; color: #8b949e; }
101
+ .finding-card { background: #161b22; border: 1px solid #30363d; border-left: 3px solid #30363d; border-radius: 8px; margin-bottom: 0.5rem; padding: 0.75rem 1rem; }
102
+ .finding-header { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
103
+ .change-badge { padding: 0.15rem 0.6rem; border-radius: 4px; font-size: 0.7rem; font-weight: 800; color: #fff; letter-spacing: 0.04em; }
104
+ .risk-badge { padding: 0.15rem 0.6rem; border-radius: 4px; font-size: 0.7rem; font-weight: 800; color: #fff; }
105
+ .finding-title { flex: 1; font-weight: 600; color: #e6edf3; font-size: 0.9rem; }
106
+ .finding-category { font-size: 0.75rem; color: #8b949e; }
107
+ .detail-diff { margin-top: 0.5rem; font-size: 0.82rem; display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
108
+ .diff-before { background: rgba(220,38,38,0.1); border: 1px solid rgba(220,38,38,0.3); border-radius: 4px; padding: 0.5rem; }
109
+ .diff-after { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); border-radius: 4px; padding: 0.5rem; }
110
+ .unchanged-section { opacity: 0.5; }
111
+ .metric-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
112
+ .metric-table th { background: #1c2128; color: #8b949e; text-align: left; padding: 0.4rem 0.75rem; border-bottom: 1px solid #30363d; font-weight: 600; }
113
+ .metric-table td { padding: 0.4rem 0.75rem; border-bottom: 1px solid #21262d; }
114
+ .metric-table tr:last-child td { border-bottom: none; }
115
+ section { margin-bottom: 2rem; }
116
+ </style>
117
+ </head>
118
+ <body>
119
+ <h1>Salesforce Audit Diff</h1>
120
+ <div class="meta">
121
+ <span>Org: <strong style="color:#c9d1d9">${esc(baseline.orgName)}</strong> (${esc(baseline.orgId)})</span>
122
+ <span>Baseline: ${fmtDate(baseline.generatedAt)}</span>
123
+ <span>Current: ${fmtDate(current.generatedAt)}</span>
124
+ </div>
125
+
126
+ <div class="scorecard">
127
+ <div>
128
+ <div class="score-delta">${scoreDeltaStr}</div>
129
+ <div style="font-size:0.8rem;color:#8b949e;margin-top:0.25rem">score change</div>
130
+ </div>
131
+ <div class="grade-delta">${esc(diff.gradeDelta)}</div>
132
+ <div class="summary-counts">
133
+ <div class="count-badge"><span class="num" style="color:#dc2626">${changeCounts.new}</span><span class="lbl">New</span></div>
134
+ <div class="count-badge"><span class="num" style="color:#22c55e">${changeCounts.resolved}</span><span class="lbl">Resolved</span></div>
135
+ <div class="count-badge"><span class="num" style="color:#d97706">${changeCounts['severity-changed']}</span><span class="lbl">Sev. Changed</span></div>
136
+ <div class="count-badge"><span class="num" style="color:#64748b">${changeCounts['detail-changed']}</span><span class="lbl">Detail Changed</span></div>
137
+ </div>
138
+ </div>
139
+
140
+ ${metricsSection}
141
+ ${sections}
142
+
143
+ <script>
144
+ // Toggle unchanged findings visibility
145
+ const unchanged = document.querySelector('.unchanged-section');
146
+ if (unchanged) {
147
+ const toggle = document.createElement('button');
148
+ toggle.textContent = 'Show Unchanged';
149
+ toggle.style.cssText = 'background:#1c2128;border:1px solid #30363d;color:#8b949e;padding:0.3rem 0.75rem;border-radius:20px;cursor:pointer;font-size:0.8rem;margin-bottom:0.75rem';
150
+ unchanged.insertBefore(toggle, unchanged.querySelector('h2').nextSibling);
151
+ let visible = false;
152
+ unchanged.querySelectorAll('.finding-card').forEach(c => c.style.display = 'none');
153
+ toggle.addEventListener('click', () => {
154
+ visible = !visible;
155
+ toggle.textContent = visible ? 'Hide Unchanged' : 'Show Unchanged';
156
+ unchanged.querySelectorAll('.finding-card').forEach(c => c.style.display = visible ? '' : 'none');
157
+ });
158
+ }
159
+ </script>
160
+ </body>
161
+ </html>`;
162
+ }
163
+ }
164
+ //# sourceMappingURL=DiffHtmlRenderer.js.map
@@ -0,0 +1,8 @@
1
+ import type { AuditDiff } from '../history/AuditDiff.js';
2
+ import type { DiffRenderer } from './DiffRenderer.js';
3
+ export declare class DiffJsonRenderer implements DiffRenderer {
4
+ readonly format = "json";
5
+ readonly fileExtension = ".json";
6
+ render(diff: AuditDiff): string;
7
+ }
8
+ //# sourceMappingURL=DiffJsonRenderer.d.ts.map
@@ -0,0 +1,8 @@
1
+ export class DiffJsonRenderer {
2
+ format = 'json';
3
+ fileExtension = '.json';
4
+ render(diff) {
5
+ return JSON.stringify(diff, null, 2);
6
+ }
7
+ }
8
+ //# sourceMappingURL=DiffJsonRenderer.js.map
@@ -0,0 +1,7 @@
1
+ import type { AuditDiff } from '../history/AuditDiff.js';
2
+ export interface DiffRenderer {
3
+ readonly format: string;
4
+ readonly fileExtension: string;
5
+ render(diff: AuditDiff): string;
6
+ }
7
+ //# sourceMappingURL=DiffRenderer.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=DiffRenderer.js.map
@@ -0,0 +1,6 @@
1
+ import type { AuditResult } from '../findings/AuditResult.js';
2
+ export declare class HistoryRenderer {
3
+ renderTable(results: AuditResult[]): string;
4
+ renderHtml(results: AuditResult[]): string;
5
+ }
6
+ //# sourceMappingURL=HistoryRenderer.d.ts.map
@@ -0,0 +1,140 @@
1
+ function fmtDate(d) {
2
+ return d.toISOString().replace('T', ' ').substring(0, 16);
3
+ }
4
+ function countBySeverity(result, level) {
5
+ return result.findings.filter((f) => f.riskLevel === level).length;
6
+ }
7
+ export class HistoryRenderer {
8
+ renderTable(results) {
9
+ if (results.length === 0)
10
+ return 'No audit history found.';
11
+ const orgName = results[0].orgName;
12
+ const orgId = results[0].orgId;
13
+ const header = `Audit History: ${orgName} (${orgId})`;
14
+ const divider = '─'.repeat(Math.max(header.length, 80));
15
+ const colHeader = ' # Date Score Grade CRIT HIGH MED LOW Δ Score';
16
+ const rows = results.map((r, i) => {
17
+ const prev = i > 0 ? results[i - 1] : null;
18
+ const delta = prev ? (r.healthScore - prev.healthScore >= 0 ? `+${r.healthScore - prev.healthScore}` : `${r.healthScore - prev.healthScore}`) : '—';
19
+ const crit = String(countBySeverity(r, 'CRITICAL')).padStart(4);
20
+ const high = String(countBySeverity(r, 'HIGH')).padStart(4);
21
+ const med = String(countBySeverity(r, 'MEDIUM')).padStart(6);
22
+ const low = String(countBySeverity(r, 'LOW')).padStart(6);
23
+ return ` ${String(i + 1).padStart(2)} ${fmtDate(r.generatedAt).padEnd(20)} ${String(r.healthScore).padStart(5)} ${r.grade.padEnd(5)} ${crit} ${high} ${med} ${low} ${String(delta).padStart(7)}`;
24
+ });
25
+ const scores = results.map((r) => r.healthScore);
26
+ const best = Math.max(...scores);
27
+ const worst = Math.min(...scores);
28
+ const trend = scores[scores.length - 1] - scores[0];
29
+ const trendStr = trend >= 0 ? `▲ +${trend}` : `▼ ${trend}`;
30
+ const bestDate = fmtDate(results[scores.indexOf(best)].generatedAt);
31
+ const worstDate = fmtDate(results[scores.indexOf(worst)].generatedAt);
32
+ const summary = ` Trend: ${trendStr} over ${results.length} audit${results.length !== 1 ? 's' : ''} Best: ${best} (${bestDate}) Worst: ${worst} (${worstDate})`;
33
+ return [header, divider, colHeader, divider, ...rows, divider, summary].join('\n');
34
+ }
35
+ renderHtml(results) {
36
+ if (results.length === 0)
37
+ return '<!DOCTYPE html><html><body><p>No audit history found.</p></body></html>';
38
+ const orgName = results[0].orgName;
39
+ const orgId = results[0].orgId;
40
+ const labels = JSON.stringify(results.map((r) => fmtDate(r.generatedAt)));
41
+ const scores = JSON.stringify(results.map((r) => r.healthScore));
42
+ const crits = JSON.stringify(results.map((r) => countBySeverity(r, 'CRITICAL')));
43
+ const highs = JSON.stringify(results.map((r) => countBySeverity(r, 'HIGH')));
44
+ const meds = JSON.stringify(results.map((r) => countBySeverity(r, 'MEDIUM')));
45
+ const lows = JSON.stringify(results.map((r) => countBySeverity(r, 'LOW')));
46
+ const tableRows = results.map((r, i) => {
47
+ const prev = i > 0 ? results[i - 1] : null;
48
+ const delta = prev ? (r.healthScore - prev.healthScore >= 0 ? `+${r.healthScore - prev.healthScore}` : `${r.healthScore - prev.healthScore}`) : '—';
49
+ const deltaColor = prev ? (r.healthScore >= prev.healthScore ? '#22c55e' : '#dc2626') : '#8b949e';
50
+ return `<tr>
51
+ <td>${i + 1}</td>
52
+ <td>${fmtDate(r.generatedAt)}</td>
53
+ <td style="text-align:right;font-weight:700">${r.healthScore}</td>
54
+ <td style="text-align:center">${r.grade}</td>
55
+ <td style="text-align:right;color:#dc2626">${countBySeverity(r, 'CRITICAL')}</td>
56
+ <td style="text-align:right;color:#ea580c">${countBySeverity(r, 'HIGH')}</td>
57
+ <td style="text-align:right;color:#d97706">${countBySeverity(r, 'MEDIUM')}</td>
58
+ <td style="text-align:right;color:#2563eb">${countBySeverity(r, 'LOW')}</td>
59
+ <td style="text-align:right;color:${deltaColor};font-weight:700">${delta}</td>
60
+ </tr>`;
61
+ }).join('');
62
+ return `<!DOCTYPE html>
63
+ <html lang="en">
64
+ <head>
65
+ <meta charset="UTF-8">
66
+ <meta name="viewport" content="width=device-width,initial-scale=1">
67
+ <title>SF Audit History — ${orgName}</title>
68
+ <script src="https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js"></script>
69
+ <style>
70
+ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
71
+ body { font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; background: #0d1117; color: #c9d1d9; max-width: 1100px; margin: 2rem auto; padding: 0 1.25rem 4rem; line-height: 1.6; }
72
+ h1 { color: #f0f6fc; font-size: 1.5rem; font-weight: 700; margin-bottom: 0.4rem; }
73
+ h2 { color: #e6edf3; font-size: 1.1rem; font-weight: 700; margin: 2rem 0 1rem; }
74
+ .meta { font-size: 0.8rem; color: #8b949e; margin-bottom: 2rem; }
75
+ .charts { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 2rem; }
76
+ .chart-box { background: #161b22; border: 1px solid #30363d; border-radius: 12px; padding: 1.25rem; }
77
+ canvas { max-height: 280px; }
78
+ table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
79
+ th { background: #1c2128; color: #8b949e; text-align: left; padding: 0.4rem 0.75rem; border-bottom: 1px solid #30363d; font-weight: 600; }
80
+ td { padding: 0.4rem 0.75rem; border-bottom: 1px solid #21262d; }
81
+ tr:last-child td { border-bottom: none; }
82
+ @media(max-width:640px) { .charts { grid-template-columns: 1fr; } }
83
+ </style>
84
+ </head>
85
+ <body>
86
+ <h1>Salesforce Audit History</h1>
87
+ <div class="meta">Org: <strong style="color:#c9d1d9">${orgName}</strong> (${orgId})</div>
88
+
89
+ <div class="charts">
90
+ <div class="chart-box">
91
+ <h2>Score Trend</h2>
92
+ <canvas id="scoreChart"></canvas>
93
+ </div>
94
+ <div class="chart-box">
95
+ <h2>Findings by Severity</h2>
96
+ <canvas id="findingsChart"></canvas>
97
+ </div>
98
+ </div>
99
+
100
+ <h2>Run History</h2>
101
+ <table>
102
+ <thead><tr><th>#</th><th>Date</th><th style="text-align:right">Score</th><th style="text-align:center">Grade</th><th style="text-align:right">CRIT</th><th style="text-align:right">HIGH</th><th style="text-align:right">MED</th><th style="text-align:right">LOW</th><th style="text-align:right">Δ Score</th></tr></thead>
103
+ <tbody>${tableRows}</tbody>
104
+ </table>
105
+
106
+ <script>
107
+ const labels = ${labels};
108
+ const scores = ${scores};
109
+ const crits = ${crits};
110
+ const highs = ${highs};
111
+ const meds = ${meds};
112
+ const lows = ${lows};
113
+
114
+ const chartDefaults = { responsive: true, plugins: { legend: { labels: { color: '#8b949e' } } }, scales: { x: { ticks: { color: '#8b949e' }, grid: { color: '#21262d' } }, y: { ticks: { color: '#8b949e' }, grid: { color: '#21262d' } } } };
115
+
116
+ new Chart(document.getElementById('scoreChart'), {
117
+ type: 'line',
118
+ data: { labels, datasets: [{ label: 'Health Score', data: scores, borderColor: '#58a6ff', backgroundColor: 'rgba(88,166,255,0.1)', tension: 0.3, fill: true, pointRadius: 4 }] },
119
+ options: { ...chartDefaults, scales: { ...chartDefaults.scales, y: { ...chartDefaults.scales.y, min: 0, max: 100 } } },
120
+ });
121
+
122
+ new Chart(document.getElementById('findingsChart'), {
123
+ type: 'bar',
124
+ data: {
125
+ labels,
126
+ datasets: [
127
+ { label: 'CRITICAL', data: crits, backgroundColor: '#dc2626' },
128
+ { label: 'HIGH', data: highs, backgroundColor: '#ea580c' },
129
+ { label: 'MEDIUM', data: meds, backgroundColor: '#d97706' },
130
+ { label: 'LOW', data: lows, backgroundColor: '#2563eb' },
131
+ ],
132
+ },
133
+ options: { ...chartDefaults, scales: { ...chartDefaults.scales, x: { ...chartDefaults.scales.x, stacked: true }, y: { ...chartDefaults.scales.y, stacked: true } } },
134
+ });
135
+ </script>
136
+ </body>
137
+ </html>`;
138
+ }
139
+ }
140
+ //# sourceMappingURL=HistoryRenderer.js.map
@@ -3,6 +3,7 @@ import type { AuditRenderer } from './AuditRenderer.js';
3
3
  export declare class HtmlRenderer implements AuditRenderer {
4
4
  readonly format = "html";
5
5
  readonly fileExtension = ".html";
6
+ private renderAttackPaths;
6
7
  render(result: AuditResult): string;
7
8
  }
8
9
  //# sourceMappingURL=HtmlRenderer.d.ts.map