()
| 162 | } |
| 163 | |
| 164 | async function readConfig(): Promise<NpsConfig | undefined> { |
| 165 | const data = await fs.promises |
| 166 | .readFile(getConfigPath(), 'utf-8') |
| 167 | .catch((err) => (err.code === 'ENOENT' ? Promise.resolve(undefined) : Promise.reject(err))) |
| 168 | if (data === undefined) { |
| 169 | return undefined |
| 170 | } |
| 171 | |
| 172 | const obj = JSON.parse(data) |
| 173 | if ( |
| 174 | obj.acknowledgedTimeframe && |
| 175 | typeof obj.acknowledgedTimeframe.start === 'string' && |
| 176 | typeof obj.acknowledgedTimeframe.end === 'string' |
| 177 | ) { |
| 178 | return obj |
| 179 | } else { |
| 180 | throw new Error('Invalid NPS config schema') |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | async function writeConfig(config: NpsConfig) { |
| 185 | const configPath = getConfigPath() |
no test coverage detected