cc-env-checker 0.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.
package/src/report.js ADDED
@@ -0,0 +1,165 @@
1
+ import { RISK_PRIORITY, STATUS_PRIORITY } from './types.js';
2
+
3
+ const ARTICLE_MODEL = [
4
+ {
5
+ id: 'persistent-identifiers',
6
+ title: 'Persistent identifiers',
7
+ titleKey: 'coverage.persistent-identifiers.title',
8
+ relatedCheckIds: ['artifacts.identity-summary'],
9
+ },
10
+ {
11
+ id: 'message-request-fingerprinting',
12
+ title: 'Message and request fingerprinting',
13
+ titleKey: 'coverage.message-request-fingerprinting.title',
14
+ relatedCheckIds: ['static-install.header-summary'],
15
+ },
16
+ {
17
+ id: 'environment-fingerprinting',
18
+ title: 'Environment fingerprint collection',
19
+ titleKey: 'coverage.environment-fingerprinting.title',
20
+ relatedCheckIds: ['fingerprint.environment-signals', 'fingerprint.runtime-inventory'],
21
+ },
22
+ {
23
+ id: 'telemetry-event-logging',
24
+ title: 'Telemetry and event logging',
25
+ titleKey: 'coverage.telemetry-event-logging.title',
26
+ relatedCheckIds: ['artifacts.telemetry-cache', 'static-install.endpoint-summary'],
27
+ },
28
+ {
29
+ id: 'third-party-analytics-channels',
30
+ title: 'Third-party analytics channels',
31
+ titleKey: 'coverage.third-party-analytics-channels.title',
32
+ relatedCheckIds: ['static-install.endpoint-summary'],
33
+ },
34
+ {
35
+ id: 'remote-policy-settings-control',
36
+ title: 'Remote policy and settings control',
37
+ titleKey: 'coverage.remote-policy-settings-control.title',
38
+ relatedCheckIds: ['static-install.endpoint-summary'],
39
+ },
40
+ {
41
+ id: 'identity-linking-risk',
42
+ title: 'Identity-linking risk',
43
+ titleKey: 'coverage.identity-linking-risk.title',
44
+ relatedCheckIds: ['artifacts.identity-summary', 'artifacts.credentials-file'],
45
+ },
46
+ {
47
+ id: 'rate-limit-abuse-signals',
48
+ title: 'Rate-limit abuse signals',
49
+ titleKey: 'coverage.rate-limit-abuse-signals.title',
50
+ relatedCheckIds: ['static-install.header-summary'],
51
+ },
52
+ {
53
+ id: 'automation-abuse-signals',
54
+ title: 'Automation-abuse signals',
55
+ titleKey: 'coverage.automation-abuse-signals.title',
56
+ relatedCheckIds: ['fingerprint.environment-signals'],
57
+ },
58
+ {
59
+ id: 'client-tampering-signals',
60
+ title: 'Client-tampering signals',
61
+ titleKey: 'coverage.client-tampering-signals.title',
62
+ relatedCheckIds: ['static-install.header-summary'],
63
+ },
64
+ ];
65
+
66
+ function compareRisk(a, b) {
67
+ return (RISK_PRIORITY[b.riskLevel] ?? 0) - (RISK_PRIORITY[a.riskLevel] ?? 0);
68
+ }
69
+
70
+ export function aggregateOverallRiskLevel(results) {
71
+ if (results.some((result) => result.riskLevel === 'high')) {
72
+ return 'high';
73
+ }
74
+
75
+ if (results.some((result) => result.riskLevel === 'medium')) {
76
+ return 'medium';
77
+ }
78
+
79
+ if (results.some((result) => result.riskLevel === 'low')) {
80
+ return 'low';
81
+ }
82
+
83
+ return 'unknown';
84
+ }
85
+
86
+ export function summarizeModule(id, checks) {
87
+ const status = checks.reduce((current, check) => {
88
+ return (STATUS_PRIORITY[check.status] ?? 0) > (STATUS_PRIORITY[current] ?? 0)
89
+ ? check.status
90
+ : current;
91
+ }, 'pass');
92
+
93
+ return {
94
+ id,
95
+ status,
96
+ riskLevel: aggregateOverallRiskLevel(checks),
97
+ checks,
98
+ };
99
+ }
100
+
101
+ export function rankFindings(results) {
102
+ return [...results]
103
+ .filter((result) => result.riskLevel !== 'low' || result.status !== 'pass')
104
+ .sort((left, right) => {
105
+ const riskDiff = compareRisk(left, right);
106
+ if (riskDiff !== 0) {
107
+ return riskDiff;
108
+ }
109
+
110
+ return (STATUS_PRIORITY[right.status] ?? 0) - (STATUS_PRIORITY[left.status] ?? 0);
111
+ });
112
+ }
113
+
114
+ export function buildRecommendedActions(findings, limit = 3) {
115
+ return findings
116
+ .filter((finding) => finding.suggestion)
117
+ .slice(0, limit)
118
+ .map((finding) => ({
119
+ id: finding.id,
120
+ priority: finding.riskLevel === 'high' || finding.status === 'fail'
121
+ ? 'fix_now'
122
+ : finding.riskLevel === 'medium' || finding.status === 'warn'
123
+ ? 'review_soon'
124
+ : 'optional',
125
+ suggestion: finding.suggestion,
126
+ ...(finding.suggestionKey ? { suggestionKey: finding.suggestionKey } : {}),
127
+ ...(finding.messageParams ? { messageParams: finding.messageParams } : {}),
128
+ }));
129
+ }
130
+
131
+ export function summarizeEvidence(results) {
132
+ return results.reduce((summary, result) => {
133
+ if (result.source) {
134
+ summary.sources[result.source] = (summary.sources[result.source] ?? 0) + 1;
135
+ }
136
+ if (result.evidenceType) {
137
+ summary.confidence[result.evidenceType] = (summary.confidence[result.evidenceType] ?? 0) + 1;
138
+ }
139
+ return summary;
140
+ }, { sources: {}, confidence: {} });
141
+ }
142
+
143
+ export function buildCoverageMatrix(results) {
144
+ return ARTICLE_MODEL.map((claim) => {
145
+ const related = results.filter((result) => claim.relatedCheckIds.includes(result.id));
146
+ const state = !related.length
147
+ ? 'not_covered'
148
+ : related.some((result) => result.evidenceType === 'unverifiable')
149
+ ? 'unverifiable'
150
+ : related.every((result) => result.status === 'pass')
151
+ ? 'covered'
152
+ : 'partial';
153
+
154
+ return {
155
+ id: claim.id,
156
+ title: claim.title,
157
+ titleKey: claim.titleKey,
158
+ state,
159
+ stateKey: `coverage.state.${state}`,
160
+ rationale: related.length ? `Mapped from ${related.length} related checks` : 'No local checks implemented yet',
161
+ evidenceSources: [...new Set(related.map((result) => result.source).filter(Boolean))],
162
+ relatedCheckIds: related.map((result) => result.id),
163
+ };
164
+ });
165
+ }
package/src/types.js ADDED
@@ -0,0 +1,18 @@
1
+ export const RISK_LEVELS = ['low', 'medium', 'high', 'unknown'];
2
+ export const STATUSES = ['pass', 'warn', 'fail', 'skip'];
3
+ export const EVIDENCE_SOURCES = ['local', 'remote', 'mixed', 'local-file', 'runtime-env', 'static-install', 'inference'];
4
+ export const EVIDENCE_CONFIDENCE = ['observed', 'derived', 'partial', 'unverifiable'];
5
+
6
+ export const RISK_PRIORITY = {
7
+ unknown: 0,
8
+ low: 1,
9
+ medium: 2,
10
+ high: 3,
11
+ };
12
+
13
+ export const STATUS_PRIORITY = {
14
+ pass: 0,
15
+ skip: 1,
16
+ warn: 2,
17
+ fail: 3,
18
+ };