MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / fetchUsageData

Function fetchUsageData

cli/src/hooks/use-usage-query.ts:41–73  ·  view source on GitHub ↗
({
  authToken,
  logger = defaultLogger,
  clientEnv = env,
}: FetchUsageParams)

Source from the content-addressed store, hash-verified

39 * Fetches usage data from the API
40 */
41export async function fetchUsageData({
42 authToken,
43 logger = defaultLogger,
44 clientEnv = env,
45}: FetchUsageParams): Promise<UsageResponse> {
46 const appUrl = clientEnv.NEXT_PUBLIC_CODEBUFF_APP_URL
47 if (!appUrl) {
48 throw new Error('NEXT_PUBLIC_CODEBUFF_APP_URL is not set')
49 }
50
51 const response = await fetch(`${appUrl}/api/v1/usage`, {
52 method: 'POST',
53 headers: {
54 'Content-Type': 'application/json',
55 },
56 body: JSON.stringify({
57 fingerprintId: 'cli-usage',
58 authToken,
59 }),
60 })
61
62 if (!response.ok) {
63 logger.error(
64 { status: response.status },
65 'Failed to fetch usage data from API',
66 )
67 throw new Error(`Failed to fetch usage: ${response.status}`)
68 }
69
70 const responseBody = await response.json()
71 const data = responseBody as UsageResponse
72 return data
73}
74
75export interface UseUsageQueryDeps {
76 logger?: Logger

Callers 2

useUsageQueryFunction · 0.70

Calls 1

fetchFunction · 0.50

Tested by

no test coverage detected