(auth: Extract<Auth.Info, { type: "oauth" }>, providerID: string)
| 823 | } |
| 824 | |
| 825 | async function ensureOauthAccessToken(auth: Extract<Auth.Info, { type: "oauth" }>, providerID: string): Promise<string> { |
| 826 | let token = auth.access |
| 827 | if (!token || auth.expires <= Date.now() + TOKEN_REFRESH_BUFFER_MS) { |
| 828 | const refreshed = await refreshAccessToken(auth.refresh) |
| 829 | if (refreshed.type === "failed") { |
| 830 | throw new Error("Failed to refresh Codex token. Run `arctic auth codex` to reconnect your account.") |
| 831 | } |
| 832 | |
| 833 | const updated: Extract<Auth.Info, { type: "oauth" }> = { |
| 834 | type: "oauth", |
| 835 | access: refreshed.access, |
| 836 | refresh: refreshed.refresh, |
| 837 | expires: refreshed.expires, |
| 838 | enterpriseUrl: auth.enterpriseUrl, |
| 839 | } |
| 840 | await Auth.set(providerID, updated) |
| 841 | token = refreshed.access |
| 842 | } |
| 843 | return token |
| 844 | } |
| 845 | |
| 846 | function resolveAccountId(accountId: string | undefined, tokenSource: string): string { |
| 847 | if (accountId) return accountId |
no test coverage detected