(store: KeyValueStore, project: string)
| 49 | * silently withholding the only way into the modes. |
| 50 | */ |
| 51 | export function readWhyAnswer(store: KeyValueStore, project: string): WhyAnswer { |
| 52 | if (project.length === 0) { |
| 53 | return NEVER_ASKED; |
| 54 | } |
| 55 | let raw: string | null; |
| 56 | try { |
| 57 | raw = store.getItem(whyKey(project)); |
| 58 | } catch { |
| 59 | return NEVER_ASKED; |
| 60 | } |
| 61 | if (raw === null) { |
| 62 | return NEVER_ASKED; |
| 63 | } |
| 64 | try { |
| 65 | const parsed = JSON.parse(raw) as Record<string, unknown>; |
| 66 | if (parsed['asked'] !== true) { |
| 67 | return NEVER_ASKED; |
| 68 | } |
| 69 | const intent = parsed['intent']; |
| 70 | return typeof intent === 'string' && INTENTS.includes(intent) |
| 71 | ? { asked: true, intent: intent as WhyIntent } |
| 72 | : { asked: true }; |
| 73 | } catch { |
| 74 | return NEVER_ASKED; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /** Record the answer, or the decline. Returns what now stands. */ |
| 79 | export function recordWhyAnswer(store: KeyValueStore, project: string, intent?: WhyIntent): WhyAnswer { |
no test coverage detected