MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / fetchBootstrapAPI

Function fetchBootstrapAPI

source code/services/api/bootstrap.ts:44–111  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42type BootstrapResponse = z.infer<ReturnType<typeof bootstrapResponseSchema>>
43
44async function fetchBootstrapAPI(): Promise<BootstrapResponse | null> {
45 if (isEssentialTrafficOnly()) {
46 logForDebugging('[Bootstrap] Skipped: Nonessential traffic disabled')
47 return null
48 }
49
50 if (getAPIProvider() !== 'firstParty') {
51 logForDebugging('[Bootstrap] Skipped: 3P provider')
52 return null
53 }
54
55 // OAuth preferred (requires user:profile scope — service-key OAuth tokens
56 // lack it and would 403). Fall back to API key auth for console users.
57 const apiKey = getAnthropicApiKey()
58 const hasUsableOAuth =
59 getClaudeAIOAuthTokens()?.accessToken && hasProfileScope()
60 if (!hasUsableOAuth && !apiKey) {
61 logForDebugging('[Bootstrap] Skipped: no usable OAuth or API key')
62 return null
63 }
64
65 const endpoint = `${getOauthConfig().BASE_API_URL}/api/claude_cli/bootstrap`
66
67 // withOAuth401Retry handles the refresh-and-retry. API key users fail
68 // through on 401 (no refresh mechanism — no OAuth token to pass).
69 try {
70 return await withOAuth401Retry(async () => {
71 // Re-read OAuth each call so the retry picks up the refreshed token.
72 const token = getClaudeAIOAuthTokens()?.accessToken
73 let authHeaders: Record<string, string>
74 if (token && hasProfileScope()) {
75 authHeaders = {
76 Authorization: `Bearer ${token}`,
77 'anthropic-beta': OAUTH_BETA_HEADER,
78 }
79 } else if (apiKey) {
80 authHeaders = { 'x-api-key': apiKey }
81 } else {
82 logForDebugging('[Bootstrap] No auth available on retry, aborting')
83 return null
84 }
85
86 logForDebugging('[Bootstrap] Fetching')
87 const response = await axios.get<unknown>(endpoint, {
88 headers: {
89 'Content-Type': 'application/json',
90 'User-Agent': getClaudeCodeUserAgent(),
91 ...authHeaders,
92 },
93 timeout: 5000,
94 })
95 const parsed = bootstrapResponseSchema().safeParse(response.data)
96 if (!parsed.success) {
97 logForDebugging(
98 `[Bootstrap] Response failed validation: ${parsed.error.message}`,
99 )
100 return null
101 }

Callers 1

fetchBootstrapDataFunction · 0.85

Calls 8

isEssentialTrafficOnlyFunction · 0.85
logForDebuggingFunction · 0.85
getAPIProviderFunction · 0.85
getAnthropicApiKeyFunction · 0.85
getOauthConfigFunction · 0.85
withOAuth401RetryFunction · 0.85
getClaudeCodeUserAgentFunction · 0.85
hasProfileScopeFunction · 0.50

Tested by

no test coverage detected