axios+telemetry cleanup

This commit is contained in:
2026-04-02 15:19:11 +03:00
parent a3cbca1e11
commit 7e1eac8002
100 changed files with 3048 additions and 4491 deletions

View File

@@ -1,5 +1,5 @@
// OAuth client for handling authentication flows with Claude services
import axios from 'axios'
import { isHttpError, nativeRequest } from '../../utils/http.js'
import {
type AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
logEvent,
@@ -127,10 +127,13 @@ export async function exchangeCodeForTokens(
requestBody.expires_in = expiresIn
}
const response = await axios.post(getOauthConfig().TOKEN_URL, requestBody, {
headers: { 'Content-Type': 'application/json' },
timeout: 15000,
})
const response = await nativeRequest(getOauthConfig().TOKEN_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: requestBody,
timeout: 15000,
responseType: 'json',
})
if (response.status !== 200) {
throw new Error(
@@ -162,11 +165,14 @@ export async function refreshOAuthToken(
).join(' '),
}
try {
const response = await axios.post(getOauthConfig().TOKEN_URL, requestBody, {
headers: { 'Content-Type': 'application/json' },
timeout: 15000,
})
try {
const response = await nativeRequest(getOauthConfig().TOKEN_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: requestBody,
timeout: 15000,
responseType: 'json',
})
if (response.status !== 200) {
throw new Error(`Token refresh failed: ${response.statusText}`)
@@ -256,11 +262,11 @@ export async function refreshOAuthToken(
}
: undefined,
}
} catch (error) {
const responseBody =
axios.isAxiosError(error) && error.response?.data
? JSON.stringify(error.response.data)
: undefined
} catch (error) {
const responseBody =
isHttpError(error) && error.data
? JSON.stringify(error.data)
: undefined
logEvent('tengu_oauth_token_refresh_failure', {
error: (error as Error)
.message as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
@@ -274,11 +280,13 @@ export async function refreshOAuthToken(
}
export async function fetchAndStoreUserRoles(
accessToken: string,
): Promise<void> {
const response = await axios.get(getOauthConfig().ROLES_URL, {
headers: { Authorization: `Bearer ${accessToken}` },
})
accessToken: string,
): Promise<void> {
const response = await nativeRequest(getOauthConfig().ROLES_URL, {
method: 'GET',
headers: { Authorization: `Bearer ${accessToken}` },
responseType: 'json',
})
if (response.status !== 200) {
throw new Error(`Failed to fetch user roles: ${response.statusText}`)
@@ -311,10 +319,12 @@ export async function fetchAndStoreUserRoles(
export async function createAndStoreApiKey(
accessToken: string,
): Promise<string | null> {
try {
const response = await axios.post(getOauthConfig().API_KEY_URL, null, {
headers: { Authorization: `Bearer ${accessToken}` },
})
try {
const response = await nativeRequest(getOauthConfig().API_KEY_URL, {
method: 'POST',
headers: { Authorization: `Bearer ${accessToken}` },
responseType: 'json',
})
const apiKey = response.data?.raw_key
if (apiKey) {

View File

@@ -1,8 +1,8 @@
import axios from 'axios'
import { getOauthConfig, OAUTH_BETA_HEADER } from 'src/constants/oauth.js'
import type { OAuthProfileResponse } from 'src/services/oauth/types.js'
import { getAnthropicApiKey } from 'src/utils/auth.js'
import { getGlobalConfig } from 'src/utils/config.js'
import { nativeRequest } from 'src/utils/http.js'
import { logError } from 'src/utils/log.js'
export async function getOauthProfileFromApiKey(): Promise<
OAuthProfileResponse | undefined
@@ -16,19 +16,16 @@ export async function getOauthProfileFromApiKey(): Promise<
if (!accountUuid || !apiKey) {
return
}
const endpoint = `${getOauthConfig().BASE_API_URL}/api/claude_cli_profile`
const endpoint = `${getOauthConfig().BASE_API_URL}/api/claude_cli_profile?account_uuid=${encodeURIComponent(accountUuid)}`
try {
const response = await axios.get<OAuthProfileResponse>(endpoint, {
const { data } = await nativeRequest<OAuthProfileResponse>(endpoint, {
headers: {
'x-api-key': apiKey,
'anthropic-beta': OAUTH_BETA_HEADER,
},
params: {
account_uuid: accountUuid,
},
timeout: 10000,
})
return response.data
return data
} catch (error) {
logError(error as Error)
}
@@ -39,14 +36,14 @@ export async function getOauthProfileFromOauthToken(
): Promise<OAuthProfileResponse | undefined> {
const endpoint = `${getOauthConfig().BASE_API_URL}/api/oauth/profile`
try {
const response = await axios.get<OAuthProfileResponse>(endpoint, {
const { data } = await nativeRequest<OAuthProfileResponse>(endpoint, {
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
timeout: 10000,
})
return response.data
return data
} catch (error) {
logError(error as Error)
}