( token: string, organizationId?: string, )
| 226 | } |
| 227 | |
| 228 | export async function fetchBalance( |
| 229 | token: string, |
| 230 | organizationId?: string, |
| 231 | ): Promise<number | undefined> { |
| 232 | try { |
| 233 | const url = getUrlFromToken( |
| 234 | "https://api.matterai.so/api/profile/balance", |
| 235 | token, |
| 236 | ); |
| 237 | const headers: Record<string, string> = { |
| 238 | Authorization: `Bearer ${token}`, |
| 239 | }; |
| 240 | if (organizationId) headers["X-KiloCode-OrganizationId"] = organizationId; |
| 241 | const response = await fetch(url, { headers }); |
| 242 | if (!response.ok) return undefined; |
| 243 | const data = (await response.json()) as { balance?: number }; |
| 244 | return data.balance; |
| 245 | } catch { |
| 246 | return undefined; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /** Validate a pasted token: well-formed JWT + accepted by the profile endpoint. */ |
| 251 | export async function verifyToken(token: string): Promise<ProfileData> { |
nothing calls this directly
no test coverage detected