( rawSegments: string[], runId: string, )
| 808 | } |
| 809 | |
| 810 | function normaliseFindings( |
| 811 | rawSegments: string[], |
| 812 | runId: string, |
| 813 | ): { |
| 814 | findings: NormalisedFinding[]; |
| 815 | errors: string[]; |
| 816 | } { |
| 817 | const findings: NormalisedFinding[] = []; |
| 818 | const errors: string[] = []; |
| 819 | |
| 820 | rawSegments.forEach((segment, segmentIndex) => { |
| 821 | const candidates = parseSegment(segment, segmentIndex, errors); |
| 822 | candidates.forEach((candidate, candidateIndex) => { |
| 823 | const parsed = prowlerFindingSchema.safeParse(candidate); |
| 824 | if (!parsed.success) { |
| 825 | errors.push( |
| 826 | `Segment ${segmentIndex + 1} item ${candidateIndex + 1}: ${parsed.error.message}`, |
| 827 | ); |
| 828 | return; |
| 829 | } |
| 830 | findings.push(toNormalisedFinding(parsed.data, findings.length, runId)); |
| 831 | }); |
| 832 | }); |
| 833 | |
| 834 | return { findings, errors }; |
| 835 | } |
| 836 | |
| 837 | function parseSegment(segment: string, segmentIndex: number, errors: string[]): unknown[] { |
| 838 | const trimmed = (segment ?? '').trim(); |
no test coverage detected