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