( sessionId: string, baseUrl: string, accessToken: string, timeoutMs: number, trustedDeviceToken?: string, )
| 91 | } |
| 92 | |
| 93 | export async function fetchRemoteCredentials( |
| 94 | sessionId: string, |
| 95 | baseUrl: string, |
| 96 | accessToken: string, |
| 97 | timeoutMs: number, |
| 98 | trustedDeviceToken?: string, |
| 99 | ): Promise<RemoteCredentials | null> { |
| 100 | const url = `${baseUrl}/v1/code/sessions/${sessionId}/bridge` |
| 101 | const headers = oauthHeaders(accessToken) |
| 102 | if (trustedDeviceToken) { |
| 103 | headers['X-Trusted-Device-Token'] = trustedDeviceToken |
| 104 | } |
| 105 | let response |
| 106 | try { |
| 107 | response = await axios.post( |
| 108 | url, |
| 109 | {}, |
| 110 | { |
| 111 | headers, |
| 112 | timeout: timeoutMs, |
| 113 | validateStatus: s => s < 500, |
| 114 | }, |
| 115 | ) |
| 116 | } catch (err: unknown) { |
| 117 | logForDebugging( |
| 118 | `[code-session] /bridge request failed: ${errorMessage(err)}`, |
| 119 | ) |
| 120 | return null |
| 121 | } |
| 122 | |
| 123 | if (response.status !== 200) { |
| 124 | const detail = extractErrorDetail(response.data) |
| 125 | logForDebugging( |
| 126 | `[code-session] /bridge failed ${response.status}${detail ? `: ${detail}` : ''}`, |
| 127 | ) |
| 128 | return null |
| 129 | } |
| 130 | |
| 131 | const data: unknown = response.data |
| 132 | if ( |
| 133 | data === null || |
| 134 | typeof data !== 'object' || |
| 135 | !('worker_jwt' in data) || |
| 136 | typeof data.worker_jwt !== 'string' || |
| 137 | !('expires_in' in data) || |
| 138 | typeof data.expires_in !== 'number' || |
| 139 | !('api_base_url' in data) || |
| 140 | typeof data.api_base_url !== 'string' || |
| 141 | !('worker_epoch' in data) |
| 142 | ) { |
| 143 | logForDebugging( |
| 144 | `[code-session] /bridge response malformed (need worker_jwt, expires_in, api_base_url, worker_epoch): ${jsonStringify(data).slice(0, 200)}`, |
| 145 | ) |
| 146 | return null |
| 147 | } |
| 148 | // protojson serializes int64 as a string to avoid JS precision loss; |
| 149 | // Go may also return a number depending on encoder settings. |
| 150 | const rawEpoch = data.worker_epoch |
nothing calls this directly
no test coverage detected