MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / handleApi

Function handleApi

telemetry-dashboard/src/api.ts:795–827  ·  view source on GitHub ↗
(env: Env, url: URL)

Source from the content-addressed store, hash-verified

793 * turns what comes back into a Response.
794 */
795export async function handleApi(env: Env, url: URL): Promise<ApiResult> {
796 if (url.pathname === '/api/session') return { body: { authenticated: true } };
797 if (url.pathname === '/api/health') return health(env);
798 if (url.pathname === '/api/meta') return meta(env);
799
800 const ranged = new Set(['/api/summary', '/api/timeseries', '/api/breakdown', '/api/activation', '/api/retention']);
801 if (!ranged.has(url.pathname)) return fail('not found', 404);
802
803 const range = parseRange(url);
804 if (isApiResult(range)) return range;
805
806 try {
807 switch (url.pathname) {
808 case '/api/summary':
809 return await summary(env, range);
810 case '/api/timeseries':
811 return await timeseries(env, url, range);
812 case '/api/breakdown':
813 return await breakdown(env, url, range);
814 case '/api/activation':
815 return await activation(env, url, range);
816 case '/api/retention':
817 return await retention(env, range);
818 default:
819 return fail('not found', 404);
820 }
821 } catch (err) {
822 // The query failed, not the caller. Log the cause, tell the page something
823 // it can put in the panel, and let the other panels carry on.
824 console.error(JSON.stringify({ msg: 'api query failed', path: url.pathname, err: String(err) }));
825 return { body: { error: 'query failed' }, status: 503 };
826 }
827}

Callers 1

apiResponseFunction · 0.90

Calls 12

healthFunction · 0.85
metaFunction · 0.85
parseRangeFunction · 0.85
isApiResultFunction · 0.85
timeseriesFunction · 0.85
hasMethod · 0.80
errorMethod · 0.80
failFunction · 0.70
summaryFunction · 0.70
breakdownFunction · 0.70
activationFunction · 0.70
retentionFunction · 0.70

Tested by

no test coverage detected