(token: string)
| 142 | } |
| 143 | |
| 144 | export async function fetchProfile(token: string): Promise<ProfileData> { |
| 145 | const url = getUrlFromToken( |
| 146 | "https://api.matterai.so/axoncode/profile", |
| 147 | token, |
| 148 | ); |
| 149 | const response = await fetch(url, { |
| 150 | headers: { |
| 151 | Authorization: `Bearer ${token}`, |
| 152 | "Content-Type": "application/json", |
| 153 | }, |
| 154 | }); |
| 155 | if (!response.ok) { |
| 156 | throw new Error( |
| 157 | `Profile request failed (${response.status}). Your token may be invalid or expired.`, |
| 158 | ); |
| 159 | } |
| 160 | return (await response.json()) as ProfileData; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Extract a clean title from potentially malformed input: a plain string, |
no test coverage detected