({apiBase, token, path}: BaseApiFetchOptions)
| 12 | }; |
| 13 | |
| 14 | export async function baseApiFetch({apiBase, token, path}: BaseApiFetchOptions): Promise<Response> { |
| 15 | if (!apiBase.endsWith('/')) { |
| 16 | throw new TypeError('apiBase must end with a slash'); |
| 17 | } |
| 18 | |
| 19 | const response = await fetch( |
| 20 | new URL(path, apiBase), |
| 21 | { |
| 22 | cache: 'no-store', |
| 23 | headers: { |
| 24 | 'user-agent': 'Refined GitHub', |
| 25 | accept: 'application/vnd.github.v3+json', |
| 26 | authorization: `token ${token}`, |
| 27 | }, |
| 28 | }, |
| 29 | ); |
| 30 | |
| 31 | if (!response.ok) { |
| 32 | const details = await response.json(); |
| 33 | throw new Error(details.message); |
| 34 | } |
| 35 | |
| 36 | return response; |
| 37 | } |
| 38 | |
| 39 | export const tokenUser = new CachedFunction('token-user', { |
| 40 | async updater(apiBase: string, token: string): Promise<string> { |
no outgoing calls
no test coverage detected