export function getAuthorization() {
    return window.localStorage.CloudflareAppsToken || null;
}
export default function request(path) {
    var optionOverrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

    var headers = {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    };
    var authorization = getAuthorization();
    if (authorization) {
        headers['authorization'] = 'Bearer ' + authorization;
    }
    var options = Object.assign({ headers: headers }, optionOverrides);
    if (typeof options.body === 'object') options.body = JSON.stringify(options.body);
    return fetch(path, options).then(function (response) {
        if (!response.ok) {
            return response.json().then(function (_ref) {
                var responseError = _ref.error;

                var error = new Error(response.statusText);
                Object.assign(error, { response: response, responseError: responseError });
                throw error;
            });
        }
        if (response.status === 204) return response; // No body
        return response.json();
    });
}
//# sourceMappingURL=request.js.map