(content: string)
| 40 | } |
| 41 | |
| 42 | function parsePluginsData(content: string): Record<string, FlaggedPlugin> { |
| 43 | const parsed = jsonParse(content) as unknown |
| 44 | if ( |
| 45 | typeof parsed !== 'object' || |
| 46 | parsed === null || |
| 47 | !('plugins' in parsed) || |
| 48 | typeof (parsed as { plugins: unknown }).plugins !== 'object' || |
| 49 | (parsed as { plugins: unknown }).plugins === null |
| 50 | ) { |
| 51 | return {} |
| 52 | } |
| 53 | const plugins = (parsed as { plugins: Record<string, unknown> }).plugins |
| 54 | const result: Record<string, FlaggedPlugin> = {} |
| 55 | for (const [id, entry] of Object.entries(plugins)) { |
| 56 | if ( |
| 57 | entry && |
| 58 | typeof entry === 'object' && |
| 59 | 'flaggedAt' in entry && |
| 60 | typeof (entry as { flaggedAt: unknown }).flaggedAt === 'string' |
| 61 | ) { |
| 62 | const parsed: FlaggedPlugin = { |
| 63 | flaggedAt: (entry as { flaggedAt: string }).flaggedAt, |
| 64 | } |
| 65 | if ( |
| 66 | 'seenAt' in entry && |
| 67 | typeof (entry as { seenAt: unknown }).seenAt === 'string' |
| 68 | ) { |
| 69 | parsed.seenAt = (entry as { seenAt: string }).seenAt |
| 70 | } |
| 71 | result[id] = parsed |
| 72 | } |
| 73 | } |
| 74 | return result |
| 75 | } |
| 76 | |
| 77 | async function readFromDisk(): Promise<Record<string, FlaggedPlugin>> { |
| 78 | try { |
no test coverage detected