(ccshareId: string)
| 78 | } |
| 79 | |
| 80 | async function fetchCcsharePayload(ccshareId: string): Promise<unknown> { |
| 81 | await getAuthRuntime().resolveSession({ allowRefresh: true }) |
| 82 | |
| 83 | const urls = buildCcshareCandidateUrls(ccshareId) |
| 84 | const failures: string[] = [] |
| 85 | |
| 86 | for (const url of urls) { |
| 87 | try { |
| 88 | const response = await withOAuth401Retry(() => { |
| 89 | const authResult = getAuthHeaders() |
| 90 | if (authResult.error) { |
| 91 | throw new Error(`Failed to get auth headers: ${authResult.error}`) |
| 92 | } |
| 93 | return axios.get<string>(url, { |
| 94 | headers: { |
| 95 | ...authResult.headers, |
| 96 | Accept: 'application/json, text/plain;q=0.9, */*;q=0.1', |
| 97 | 'User-Agent': getUserAgent(), |
| 98 | }, |
| 99 | timeout: 15000, |
| 100 | responseType: 'text', |
| 101 | transformResponse: value => value, |
| 102 | }) |
| 103 | }, { |
| 104 | also403Revoked: true, |
| 105 | }) |
| 106 | |
| 107 | logForDebugging(`ccshare fetch succeeded: ${url}`, { level: 'info' }) |
| 108 | return parseTransportPayload(response.data) |
| 109 | } catch (error) { |
| 110 | const status = axios.isAxiosError(error) ? error.response?.status : null |
| 111 | const detail = |
| 112 | status !== undefined && status !== null |
| 113 | ? `${url} -> HTTP ${status}` |
| 114 | : `${url} -> ${errorMessage(error)}` |
| 115 | failures.push(detail) |
| 116 | logForDebugging(`ccshare fetch failed: ${detail}`, { level: 'warn' }) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | throw new Error( |
| 121 | `Unable to fetch shared transcript. Tried ${urls.length} endpoint${urls.length === 1 ? '' : 's'}: ${failures.join('; ')}`, |
| 122 | ) |
| 123 | } |
| 124 | |
| 125 | export function buildCcshareCandidateUrls(ccshareId: string): string[] { |
| 126 | const encoded = encodeURIComponent(ccshareId) |
no test coverage detected