({
settings,
auth,
path,
method,
body,
}: {
settings: ExtensionSettings;
auth: ExtensionAuth;
path: string;
method: "GET" | "POST" | "DELETE";
body?: unknown;
})
| 78 | } |
| 79 | |
| 80 | const 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 | |
| 110 | export const createAuthStart = async (settings: ExtensionSettings) => { |
| 111 | const redirectUri = chrome.identity.getRedirectURL(); |
no test coverage detected