(path = credentialPath())
| 193 | |
| 194 | /** Remove only the `oauth` block. Used by `auth logout --keep-api-key`. */ |
| 195 | export async function clearOAuth(path = credentialPath()): Promise<void> { |
| 196 | const { credentials, source } = await readStore(path); |
| 197 | if (source === "absent" || !credentials.oauth) return; |
| 198 | // Drop oauth, keep everything else (api_key, the friendly-display |
| 199 | // user block, and any unknown/foreign keys) so a logout that only |
| 200 | // clears the OAuth session doesn't silently wipe co-located data. |
| 201 | const next: Credentials = { ...credentials }; |
| 202 | delete next.oauth; |
| 203 | if (!next.api_key && !hasPreservedUnknownData(next)) { |
| 204 | // Nothing worth preserving survives. The leftover user block had no |
| 205 | // friendly fields and there's no foreign/unknown data to round-trip, |
| 206 | // so this is orphaned metadata with no credential to attach to — drop |
| 207 | // the file. (A surviving top-level / user-block unknown key, by |
| 208 | // contrast, may be a future credential another CLI owns, so we keep |
| 209 | // the file in that case.) |
| 210 | await deleteStore(path); |
| 211 | return; |
| 212 | } |
| 213 | await writeStore(next, path); |
| 214 | } |
| 215 | |
| 216 | async function ensureDir(dir: string): Promise<void> { |
| 217 | try { |
no test coverage detected