(config: Config, _flags: GlobalFlags)
| 16 | 'mmx auth refresh', |
| 17 | ], |
| 18 | async run(config: Config, _flags: GlobalFlags) { |
| 19 | const creds = await loadCredentials(); |
| 20 | |
| 21 | if (!creds) { |
| 22 | throw new CLIError( |
| 23 | 'Not applicable: not authenticated via OAuth.', |
| 24 | ExitCode.USAGE, |
| 25 | 'Run mmx auth login first.', |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | if (config.dryRun) { |
| 30 | console.log('Would refresh OAuth token.'); |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | const fresh = await refreshAccessToken(creds.refresh_token, creds.region ?? 'global'); |
| 35 | |
| 36 | const updated: CredentialFile = { |
| 37 | access_token: fresh.access_token, |
| 38 | refresh_token: fresh.refresh_token, |
| 39 | expires_at: fresh.expires_at, |
| 40 | region: creds.region, |
| 41 | resource_url: fresh.resource_url ?? creds.resource_url, |
| 42 | account: creds.account, |
| 43 | }; |
| 44 | |
| 45 | await saveCredentials(updated); |
| 46 | |
| 47 | const format = detectOutputFormat(config.output); |
| 48 | |
| 49 | if (config.quiet) { |
| 50 | console.log(updated.expires_at); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | console.log(formatOutput({ |
| 55 | status: 'Token refreshed', |
| 56 | expires: updated.expires_at, |
| 57 | }, format)); |
| 58 | }, |
| 59 | }); |
nothing calls this directly
no test coverage detected