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) {