MCPcopy
hub / github.com/opactorai/Claudable / vercelFetch

Function vercelFetch

lib/services/vercel.ts:23–76  ·  view source on GitHub ↗
(
  token: string,
  endpoint: string,
  {
    method = 'GET',
    body,
    teamId,
    query,
  }: {
    method?: string;
    body?: any;
    teamId?: string | null;
    query?: Record<string, string | undefined>;
  } = {},
)

Source from the content-addressed store, hash-verified

21}
22
23async function vercelFetch<T = any>(
24 token: string,
25 endpoint: string,
26 {
27 method = 'GET',
28 body,
29 teamId,
30 query,
31 }: {
32 method?: string;
33 body?: any;
34 teamId?: string | null;
35 query?: Record<string, string | undefined>;
36 } = {},
37): Promise<T> {
38 const url = new URL(`${VERCEL_API_BASE}${endpoint}`);
39 if (teamId) {
40 url.searchParams.set('teamId', teamId);
41 }
42 if (query) {
43 Object.entries(query).forEach(([key, value]) => {
44 if (value !== undefined && value !== null) {
45 url.searchParams.set(key, value);
46 }
47 });
48 }
49
50 const headers: Record<string, string> = {
51 Authorization: `Bearer ${token}`,
52 };
53
54 let resolvedBody: BodyInit | undefined;
55 if (body !== undefined && body !== null) {
56 headers['Content-Type'] = 'application/json';
57 resolvedBody = JSON.stringify(body);
58 }
59
60 const response = await fetch(url.toString(), {
61 method,
62 headers,
63 body: resolvedBody,
64 });
65
66 if (!response.ok) {
67 const errorText = await response.text();
68 throw new VercelError(errorText || `Vercel API request failed (${response.status})`, response.status);
69 }
70
71 if (response.status === 204) {
72 return null as T;
73 }
74
75 return (await response.json()) as T;
76}
77
78function normalizeDeploymentUrl(url?: string | null): string | null {
79 if (!url) return null;

Callers 1

connectVercelProjectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected