MCPcopy
hub / github.com/CapSoftware/Cap / requestJson

Function requestJson

apps/chrome-extension/src/shared/api.ts:80–108  ·  view source on GitHub ↗
({
	settings,
	auth,
	path,
	method,
	body,
}: {
	settings: ExtensionSettings;
	auth: ExtensionAuth;
	path: string;
	method: "GET" | "POST" | "DELETE";
	body?: unknown;
})

Source from the content-addressed store, hash-verified

78}
79
80const requestJson = async <TResponse>({
81 settings,
82 auth,
83 path,
84 method,
85 body,
86}: {
87 settings: ExtensionSettings;
88 auth: ExtensionAuth;
89 path: string;
90 method: "GET" | "POST" | "DELETE";
91 body?: unknown;
92}) => {
93 const response = await fetch(apiUrl(settings, path), {
94 method,
95 headers: {
96 Authorization: `Bearer ${auth.authApiKey}`,
97 "Content-Type": "application/json",
98 },
99 body: body === undefined ? undefined : JSON.stringify(body),
100 signal: AbortSignal.timeout(API_REQUEST_TIMEOUT_MS),
101 });
102
103 if (!response.ok) {
104 throw new ApiRequestError(response.status, await response.text());
105 }
106
107 return (await response.json()) as TResponse;
108};
109
110export const createAuthStart = async (settings: ExtensionSettings) => {
111 const redirectUri = chrome.identity.getRedirectURL();

Callers 5

revokeAuthFunction · 0.85
fetchBootstrapFunction · 0.85
createInstantRecordingFunction · 0.85
updateUploadProgressFunction · 0.85
deleteInstantRecordingFunction · 0.85

Calls 2

apiUrlFunction · 0.85
fetchFunction · 0.50

Tested by

no test coverage detected