(tokens: TokenData)
| 32 | const CREDENTIALS_MODE = 0o600; |
| 33 | |
| 34 | export function saveTokens(tokens: TokenData): void { |
| 35 | const credentialsFile = getCredentialsFilePath(); |
| 36 | migrateLegacyFileSync(CREDENTIALS_FILE_NAME, credentialsFile, CREDENTIALS_MODE); |
| 37 | ensureConfigDir(); |
| 38 | const data = { |
| 39 | ...tokens, |
| 40 | expires_at: |
| 41 | tokens.expires_at ?? (tokens.expires_in ? Date.now() + tokens.expires_in * 1000 : undefined), |
| 42 | }; |
| 43 | fs.writeFileSync(credentialsFile, JSON.stringify(data, null, 2), { mode: CREDENTIALS_MODE }); |
| 44 | // `mode` is ignored when the file already exists; enforce it explicitly. |
| 45 | fs.chmodSync(credentialsFile, CREDENTIALS_MODE); |
| 46 | } |
| 47 | |
| 48 | export function loadTokens(): TokenData | null { |
| 49 | const credentialsFile = resolveReadPathSync( |
no test coverage detected