(options: { stateDir: string })
| 274 | } |
| 275 | |
| 276 | export function readCliSession(options: { stateDir: string }): CliSessionRecord | null { |
| 277 | const filePath = resolveCliSessionPath(options.stateDir); |
| 278 | if (!fs.existsSync(filePath)) return null; |
| 279 | try { |
| 280 | const parsed = JSON.parse(fs.readFileSync(filePath, 'utf8')) as Partial<CliSessionRecord>; |
| 281 | if ( |
| 282 | parsed.version !== 1 || |
| 283 | !hasToken(parsed.id) || |
| 284 | !hasToken(parsed.cloudBaseUrl) || |
| 285 | !hasToken(parsed.refreshCredential) || |
| 286 | !hasToken(parsed.createdAt) |
| 287 | ) { |
| 288 | return null; |
| 289 | } |
| 290 | return parsed as CliSessionRecord; |
| 291 | } catch { |
| 292 | return null; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | export function writeCliSession(options: { stateDir: string; session: CliSessionRecord }): void { |
| 297 | const filePath = resolveCliSessionPath(options.stateDir); |
no test coverage detected