@mitre/hdf-schema 2.0.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 (65) hide show
  1. package/LICENSE.md +55 -0
  2. package/README.md +143 -0
  3. package/dist/go/go.mod +4 -0
  4. package/dist/go/hdf.go +2224 -0
  5. package/dist/helpers.d.ts +77 -0
  6. package/dist/helpers.js +242 -0
  7. package/dist/index.d.ts +62 -0
  8. package/dist/index.js +37 -0
  9. package/dist/python/hdf_amendments.py +695 -0
  10. package/dist/python/hdf_baseline.py +782 -0
  11. package/dist/python/hdf_comparison.py +1771 -0
  12. package/dist/python/hdf_evidence_package.py +593 -0
  13. package/dist/python/hdf_plan.py +363 -0
  14. package/dist/python/hdf_results.py +2163 -0
  15. package/dist/python/hdf_system.py +904 -0
  16. package/dist/schemas/hdf-amendments.schema.json +1562 -0
  17. package/dist/schemas/hdf-baseline.schema.json +1787 -0
  18. package/dist/schemas/hdf-comparison.schema.json +3730 -0
  19. package/dist/schemas/hdf-evidence-package.schema.json +1738 -0
  20. package/dist/schemas/hdf-plan.schema.json +1821 -0
  21. package/dist/schemas/hdf-results.schema.json +2810 -0
  22. package/dist/schemas/hdf-system.schema.json +2512 -0
  23. package/dist/ts/hdf-amendments.d.ts +446 -0
  24. package/dist/ts/hdf-amendments.js +77 -0
  25. package/dist/ts/hdf-amendments.ts +457 -0
  26. package/dist/ts/hdf-baseline.d.ts +472 -0
  27. package/dist/ts/hdf-baseline.js +58 -0
  28. package/dist/ts/hdf-baseline.ts +483 -0
  29. package/dist/ts/hdf-comparison.d.ts +1185 -0
  30. package/dist/ts/hdf-comparison.js +216 -0
  31. package/dist/ts/hdf-comparison.ts +1210 -0
  32. package/dist/ts/hdf-evidence-package.d.ts +348 -0
  33. package/dist/ts/hdf-evidence-package.js +39 -0
  34. package/dist/ts/hdf-evidence-package.ts +356 -0
  35. package/dist/ts/hdf-plan.d.ts +204 -0
  36. package/dist/ts/hdf-plan.js +23 -0
  37. package/dist/ts/hdf-plan.ts +205 -0
  38. package/dist/ts/hdf-results.d.ts +1457 -0
  39. package/dist/ts/hdf-results.js +174 -0
  40. package/dist/ts/hdf-results.ts +1481 -0
  41. package/dist/ts/hdf-system.d.ts +609 -0
  42. package/dist/ts/hdf-system.js +102 -0
  43. package/dist/ts/hdf-system.ts +617 -0
  44. package/package.json +98 -0
  45. package/src/schemas/hdf-amendments.schema.json +97 -0
  46. package/src/schemas/hdf-baseline.schema.json +190 -0
  47. package/src/schemas/hdf-comparison.schema.json +107 -0
  48. package/src/schemas/hdf-evidence-package.schema.json +227 -0
  49. package/src/schemas/hdf-plan.schema.json +92 -0
  50. package/src/schemas/hdf-results.schema.json +304 -0
  51. package/src/schemas/hdf-system.schema.json +136 -0
  52. package/src/schemas/primitives/amendments.schema.json +155 -0
  53. package/src/schemas/primitives/common.schema.json +814 -0
  54. package/src/schemas/primitives/comparison.schema.json +809 -0
  55. package/src/schemas/primitives/component.schema.json +518 -0
  56. package/src/schemas/primitives/data-flow.schema.json +158 -0
  57. package/src/schemas/primitives/extensions.schema.json +342 -0
  58. package/src/schemas/primitives/parameter.schema.json +128 -0
  59. package/src/schemas/primitives/plan.schema.json +128 -0
  60. package/src/schemas/primitives/platform.schema.json +32 -0
  61. package/src/schemas/primitives/result.schema.json +133 -0
  62. package/src/schemas/primitives/runner.schema.json +83 -0
  63. package/src/schemas/primitives/statistics.schema.json +71 -0
  64. package/src/schemas/primitives/system.schema.json +132 -0
  65. package/src/schemas/primitives/target.schema.json +523 -0
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Helper functions for creating valid HDF objects with sensible defaults
3
+ * Type definitions for helpers.js
4
+ */
5
+
6
+ import type {
7
+ EvaluatedBaseline,
8
+ EvaluatedRequirement,
9
+ RequirementResult,
10
+ Checksum,
11
+ Integrity,
12
+ Description,
13
+ SourceLocation,
14
+ ResultStatus,
15
+ SupportedPlatform,
16
+ RequirementGroup,
17
+ } from '../dist/ts/hdf-results.js';
18
+
19
+ export function createMinimalBaseline(
20
+ name: string,
21
+ requirements: EvaluatedRequirement[],
22
+ options?: {
23
+ title?: string;
24
+ version?: string;
25
+ attributes?: Array<Record<string, unknown>>;
26
+ groups?: RequirementGroup[];
27
+ supports?: SupportedPlatform[];
28
+ integrity?: Integrity;
29
+ resultsChecksum?: Checksum;
30
+ originalChecksum?: Checksum;
31
+ status?: string;
32
+ summary?: string;
33
+ }
34
+ ): EvaluatedBaseline;
35
+
36
+ export function createRequirement(
37
+ id: string,
38
+ title: string,
39
+ descriptions: Description[],
40
+ impact: number,
41
+ results: RequirementResult[],
42
+ options?: {
43
+ sourceLocation?: SourceLocation;
44
+ tags?: Record<string, unknown>;
45
+ }
46
+ ): EvaluatedRequirement;
47
+
48
+ export function createDescription(label: string, data: string): Description;
49
+
50
+ export function createResult(
51
+ status: ResultStatus,
52
+ message?: string,
53
+ options?: {
54
+ codeDesc?: string;
55
+ startTime?: Date;
56
+ runTime?: number;
57
+ backtrace?: string[];
58
+ exception?: string;
59
+ }
60
+ ): RequirementResult;
61
+
62
+ export function createEmptyChecksum(): Checksum;
63
+
64
+ export function createSupportedPlatform(
65
+ platform: string,
66
+ release?: string
67
+ ): SupportedPlatform;
68
+
69
+ export function createSourceLocation(ref: string, line: number): SourceLocation;
70
+
71
+ export function severityToImpact(severity: string): number;
72
+
73
+ export function impactToSeverity(impact: number): string;
74
+
75
+ export function computeEffectiveStatus(
76
+ requirement: EvaluatedRequirement
77
+ ): ResultStatus;
@@ -0,0 +1,242 @@
1
+ /**
2
+ * Helper functions for creating valid HDF objects with sensible defaults
3
+ * Use these in converters to ensure type safety and schema compliance
4
+ */
5
+
6
+ /**
7
+ * Create a minimal valid EvaluatedBaseline with required fields
8
+ * @param {string} name - Unique baseline identifier
9
+ * @param {import('../dist/ts/hdf-results.js').EvaluatedRequirement[]} requirements - Array of evaluated requirements
10
+ * @param {Object} [options] - Optional fields to override defaults
11
+ * @returns {import('../dist/ts/hdf-results.js').EvaluatedBaseline}
12
+ */
13
+ export function createMinimalBaseline(name, requirements, options = {}) {
14
+ const baseline = {
15
+ name,
16
+ requirements,
17
+ };
18
+
19
+ // Include optional fields only if provided
20
+ if (options.title) {
21
+ baseline.title = options.title;
22
+ }
23
+ if (options.version) {
24
+ baseline.version = options.version;
25
+ }
26
+ if (options.attributes) {
27
+ baseline.attributes = options.attributes;
28
+ }
29
+ if (options.groups) {
30
+ baseline.groups = options.groups;
31
+ }
32
+ if (options.supports) {
33
+ baseline.supports = options.supports;
34
+ }
35
+ if (options.integrity) {
36
+ baseline.integrity = options.integrity;
37
+ }
38
+ if (options.resultsChecksum) {
39
+ baseline.resultsChecksum = options.resultsChecksum;
40
+ }
41
+ if (options.originalChecksum) {
42
+ baseline.originalChecksum = options.originalChecksum;
43
+ }
44
+ if (options.status) {
45
+ baseline.status = options.status;
46
+ }
47
+ if (options.summary) {
48
+ baseline.summary = options.summary;
49
+ }
50
+
51
+ return baseline;
52
+ }
53
+
54
+ /**
55
+ * Create a minimal valid EvaluatedRequirement
56
+ * @param {string} id - Unique requirement identifier
57
+ * @param {string} title - Human-readable title
58
+ * @param {import('../dist/ts/hdf-results.js').Description[]} descriptions - Array of descriptions
59
+ * @param {number} impact - Impact score (0.0 to 1.0)
60
+ * @param {import('../dist/ts/hdf-results.js').RequirementResult[]} results - Array of test results
61
+ * @param {Object} [options] - Optional fields
62
+ * @returns {import('../dist/ts/hdf-results.js').EvaluatedRequirement}
63
+ */
64
+ export function createRequirement(id, title, descriptions, impact, results, options = {}) {
65
+ const req = {
66
+ id,
67
+ title,
68
+ descriptions,
69
+ impact,
70
+ results,
71
+ tags: options.tags || {},
72
+ };
73
+
74
+ // Only include sourceLocation if it's provided
75
+ if (options.sourceLocation) {
76
+ req.sourceLocation = options.sourceLocation;
77
+ }
78
+
79
+ return req;
80
+ }
81
+
82
+ /**
83
+ * Create a description object
84
+ * @param {string} label - Description label ('default', 'check', 'fix', 'rationale', etc.)
85
+ * @param {string} data - Description text
86
+ * @returns {import('../dist/ts/hdf-results.js').Description}
87
+ */
88
+ export function createDescription(label, data) {
89
+ return { label, data };
90
+ }
91
+
92
+ /**
93
+ * Create a RequirementResult
94
+ * @param {import('../dist/ts/hdf-results.js').ResultStatus} status - Test result status
95
+ * @param {string} [message] - Optional message explaining the result
96
+ * @param {Object} [options] - Optional fields
97
+ * @returns {import('../dist/ts/hdf-results.js').RequirementResult}
98
+ */
99
+ export function createResult(status, message = '', options = {}) {
100
+ return {
101
+ status,
102
+ message,
103
+ codeDesc: options.codeDesc || '',
104
+ startTime: options.startTime,
105
+ runTime: options.runTime,
106
+ backtrace: options.backtrace,
107
+ exception: options.exception,
108
+ };
109
+ }
110
+
111
+ /**
112
+ * Create an empty checksum (for when checksum data is unavailable)
113
+ * @returns {import('../dist/ts/hdf-results.js').Checksum}
114
+ */
115
+ export function createEmptyChecksum() {
116
+ return {
117
+ algorithm: 'sha256',
118
+ value: '',
119
+ };
120
+ }
121
+
122
+ /**
123
+ * Create a supported platform object
124
+ * @param {string} platform - Platform name (e.g., 'linux', 'windows', 'aws')
125
+ * @param {string} [release] - Optional release version
126
+ * @returns {import('../dist/ts/hdf-results.js').SupportedPlatform}
127
+ */
128
+ export function createSupportedPlatform(platform, release) {
129
+ return {
130
+ platform,
131
+ release,
132
+ };
133
+ }
134
+
135
+ /**
136
+ * Create a source location reference
137
+ * @param {string} ref - File or resource reference
138
+ * @param {number} line - Line number
139
+ * @returns {import('../dist/ts/hdf-results.js').SourceLocation}
140
+ */
141
+ export function createSourceLocation(ref, line) {
142
+ return { ref, line };
143
+ }
144
+
145
+ /**
146
+ * Map a severity string to an impact score.
147
+ *
148
+ * Impact bands align with CVSS 3.x severity ratings normalized to 0-1:
149
+ * critical=0.9 (CVSS 9.0), high=0.7 (CVSS 7.0), medium=0.5 (CVSS 5.0),
150
+ * low=0.3 (CVSS 3.0), informational=0.0 (CVSS 0.0)
151
+ *
152
+ * Each value is the floor of its band, preserving sub-band precision:
153
+ * 0.9-1.0=critical, 0.7-0.8=high, 0.4-0.6=medium, 0.1-0.3=low, 0.0=informational
154
+ *
155
+ * @param {string} severity - Severity level
156
+ * @returns {number} Impact score between 0.0 and 1.0
157
+ */
158
+ export function severityToImpact(severity) {
159
+ const normalized = severity.toLowerCase();
160
+ switch (normalized) {
161
+ case 'critical':
162
+ return 0.9;
163
+ case 'high':
164
+ return 0.7;
165
+ case 'medium':
166
+ return 0.5;
167
+ case 'low':
168
+ return 0.3;
169
+ case 'informational':
170
+ case 'info':
171
+ return 0.0;
172
+ default:
173
+ return 0.5;
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Map an impact score to a severity string
179
+ * @param {number} impact - Impact score (0.0 to 1.0)
180
+ * @returns {string} Severity level
181
+ */
182
+ export function impactToSeverity(impact) {
183
+ if (impact >= 0.9) return 'critical';
184
+ if (impact >= 0.7) return 'high';
185
+ if (impact >= 0.4) return 'medium';
186
+ if (impact > 0.0) return 'low';
187
+ return 'informational';
188
+ }
189
+
190
+ /**
191
+ * Compute the effective status of a requirement from its results and impact.
192
+ *
193
+ * When effectiveStatus is already set on the requirement, returns it directly.
194
+ * Otherwise derives status using standard HDF/InSpec precedence:
195
+ * 1. effectiveStatus already set → return it
196
+ * 2. impact === 0 → notApplicable
197
+ * 3. No results → notReviewed
198
+ * 4. Any "error" result → error
199
+ * 5. Any "failed" result → failed
200
+ * 6. All "passed" → passed
201
+ * 7. Otherwise → notReviewed
202
+ *
203
+ * @param {import('../dist/ts/hdf-results.js').EvaluatedRequirement} requirement
204
+ * @returns {import('../dist/ts/hdf-results.js').ResultStatus}
205
+ */
206
+ export function computeEffectiveStatus(requirement) {
207
+ if (requirement.effectiveStatus) {
208
+ return requirement.effectiveStatus;
209
+ }
210
+
211
+ if (requirement.impact === 0) {
212
+ return 'notApplicable';
213
+ }
214
+
215
+ const results = requirement.results;
216
+ if (!results || results.length === 0) {
217
+ return 'notReviewed';
218
+ }
219
+
220
+ let hasError = false;
221
+ let hasFailed = false;
222
+ let hasPassed = false;
223
+
224
+ for (const result of results) {
225
+ switch (result.status) {
226
+ case 'error':
227
+ hasError = true;
228
+ break;
229
+ case 'failed':
230
+ hasFailed = true;
231
+ break;
232
+ case 'passed':
233
+ hasPassed = true;
234
+ break;
235
+ }
236
+ }
237
+
238
+ if (hasError) return 'error';
239
+ if (hasFailed) return 'failed';
240
+ if (hasPassed) return 'passed';
241
+ return 'notReviewed';
242
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Main entry point for @mitre/hdf-schema
3
+ * Re-exports all types from generated TypeScript definitions
4
+ */
5
+
6
+ // Re-export all types from hdf-results (includes most common types)
7
+ export * from './ts/hdf-results.js';
8
+
9
+ // Re-export baseline-only types (interfaces not in hdf-results).
10
+ // No export * from hdf-baseline — its enums (HashAlgorithm, Severity) duplicate
11
+ // hdf-results and cause ambiguous-export collisions.
12
+ export type { HdfBaseline, BaselineRequirement } from './ts/hdf-baseline.js';
13
+
14
+ // Re-export comparison-specific types (interfaces and enums not in hdf-results).
15
+ // No export * from hdf-comparison — shared types duplicate hdf-results.
16
+ export type {
17
+ HdfComparison, RequirementDiff, ComparisonSummary, Source,
18
+ Annotation, BaselineDiff, BaselineRef, FieldChange, MatchingConfig,
19
+ ScannerConflict, SeverityBreakdown, StateCounts, PerSourceSummary,
20
+ DescriptionElement, Value,
21
+ } from './ts/hdf-comparison.js';
22
+ export {
23
+ AnnotationCategory, CapturedByType, ChangeReason, ComparisonMode,
24
+ ConflictResolution, FormatVersion, MatchStrategy, Op, OriginalFormat,
25
+ RequirementState, SourceRole, State, TypeEnum,
26
+ } from './ts/hdf-comparison.js';
27
+
28
+ // Re-export system types
29
+ // No Component re-export — it's already exported by hdf-results.js via export *
30
+ export type {
31
+ HdfSystem, InputOverride, ControlDesignation, DataFlow,
32
+ } from './ts/hdf-system.js';
33
+ export {
34
+ AuthorizationStatus, BoundaryDescription, CategorizationLevel, Designation, Direction,
35
+ } from './ts/hdf-system.js';
36
+
37
+ // Re-export plan types
38
+ export type {
39
+ HdfPlan, Assessment, Schedule, RunnerConfig,
40
+ } from './ts/hdf-plan.js';
41
+ export {
42
+ PlanType,
43
+ } from './ts/hdf-plan.js';
44
+
45
+ // Re-export amendments types
46
+ export type {
47
+ HdfAmendments, StandaloneOverride,
48
+ } from './ts/hdf-amendments.js';
49
+ export {
50
+ OverrideType,
51
+ } from './ts/hdf-amendments.js';
52
+
53
+ // Re-export evidence-package types
54
+ export type {
55
+ HdfEvidencePackage, ContentReference, CompletenessCheck, SBOMCoverage,
56
+ } from './ts/hdf-evidence-package.js';
57
+ export {
58
+ ContentType,
59
+ } from './ts/hdf-evidence-package.js';
60
+
61
+ // Re-export helper functions
62
+ export * from './helpers.js';
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Main entry point for @mitre/hdf-schema
3
+ * Re-exports all types from generated TypeScript definitions
4
+ */
5
+
6
+ // Re-export all values from hdf-results (enums like ResultStatus, HashAlgorithm, Severity)
7
+ export * from './ts/hdf-results.js';
8
+
9
+ // Re-export comparison-specific enums (runtime values not in hdf-results)
10
+ export {
11
+ AnnotationCategory, CapturedByType, ChangeReason, ComparisonMode,
12
+ ConflictResolution, FormatVersion, MatchStrategy, Op, OriginalFormat,
13
+ RequirementState, SourceRole, State, TypeEnum,
14
+ } from './ts/hdf-comparison.js';
15
+
16
+ // Re-export system enums (runtime values)
17
+ export {
18
+ AuthorizationStatus, BoundaryDescription, CategorizationLevel, Designation, Direction,
19
+ } from './ts/hdf-system.js';
20
+
21
+ // Re-export plan enums (runtime values)
22
+ export {
23
+ PlanType,
24
+ } from './ts/hdf-plan.js';
25
+
26
+ // Re-export amendments enums (runtime values)
27
+ export {
28
+ OverrideType,
29
+ } from './ts/hdf-amendments.js';
30
+
31
+ // Re-export evidence-package enums (runtime values)
32
+ export {
33
+ ContentType,
34
+ } from './ts/hdf-evidence-package.js';
35
+
36
+ // Re-export helper functions
37
+ export * from './helpers.js';