MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / fetchBalance

Function fetchBalance

src/auth/auth.ts:228–248  ·  view source on GitHub ↗
(
  token: string,
  organizationId?: string,
)

Source from the content-addressed store, hash-verified

226}
227
228export 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. */
251export async function verifyToken(token: string): Promise<ProfileData> {

Callers

nothing calls this directly

Calls 1

getUrlFromTokenFunction · 0.85

Tested by

no test coverage detected