( input: string, init?: FetchAPIInit, apiVersion = '1.0', )
| 6 | } |
| 7 | |
| 8 | export const fetchAPI = async ( |
| 9 | input: string, |
| 10 | init?: FetchAPIInit, |
| 11 | apiVersion = '1.0', |
| 12 | ) => { |
| 13 | const apiUrl = `${baseApiUrl(apiVersion)}${input}`; |
| 14 | const csrfToken = getCSRFToken(); |
| 15 | |
| 16 | const headers = { |
| 17 | 'Content-Type': 'application/json', |
| 18 | ...init?.headers, |
| 19 | ...(csrfToken && { 'X-CSRFToken': csrfToken }), |
| 20 | }; |
| 21 | |
| 22 | if (init?.withoutContentType) { |
| 23 | delete headers?.['Content-Type' as keyof typeof headers]; |
| 24 | } |
| 25 | |
| 26 | return await fetch(apiUrl, { |
| 27 | ...init, |
| 28 | credentials: 'include', |
| 29 | headers, |
| 30 | }); |
| 31 | }; |
no test coverage detected