Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { _no__dom } from '@ctx-core/dom'
export default (
_no__dom()
? require('isomorphic-fetch')
: window.fetch
) as (input:RequestInfo, init?:RequestInit)=>Promise
export const Headers:Headers = _no__dom() ? require('isomorphic-fetch').Headers : window.Headers
export const Request:Request = _no__dom() ? require('isomorphic-fetch').Request : window.Request
export const Response:Response = _no__dom() ? require('isomorphic-fetch').Response : window.Response
/**
* Module wrapping the fetch http client for ctx-core
* @module @ctx-core/fetch/lib
*/
import { sleep } from '@ctx-core/sleep';
import { _number__fibonacci } from '@ctx-core/fibonacci';
import { _no__dom } from '@ctx-core/dom';
import { throw__error } from '@ctx-core/error';
import fetch from '@ctx-core/isomorphic-fetch';
import { log } from '@ctx-core/logger';
const logPrefix = '@ctx-core/fetch';
export { fetch };
export function _headers(init) {
return _no__dom() ? init : new window.Headers(init);
}
export const Request = _no__dom() ? require('isomorphic-fetch').Request : window.Request;
export const Response = _no__dom() ? require('isomorphic-fetch').Response : window.Response;
export function _method__fetch(ctx__fetch) {
return (ctx__fetch.method || 'GET').toUpperCase();
}
export function _url__fetch(ctx__fetch) {
const { url } = ctx__fetch;
return url;
}
export async function throw__response__fetch(response) {
log(`${logPrefix}|throw__response__fetch`);
const error_message = await response.text();
throw__error({
status__http: response.status,
error_message,
});
}
/**
* Module wrapping the fetch http client for ctx-core
* @module @ctx-core/fetch/lib
*/
import { sleep } from '@ctx-core/sleep'
import { _number__fibonacci } from '@ctx-core/fibonacci'
import { _no__dom } from '@ctx-core/dom'
import { throw__error } from '@ctx-core/error'
const fetch = _no__dom() ? require('isomorphic-fetch') : window.fetch
import { log } from '@ctx-core/logger'
const logPrefix = '@ctx-core/fetch'
export { fetch }
export const Headers = _no__dom() ? require('isomorphic-fetch').Headers : window.Headers
export const Request = _no__dom() ? require('isomorphic-fetch').Request : window.Request
export const Response = _no__dom() ? require('isomorphic-fetch').Response : window.Response
export function _headers(init) {
return _no__dom() ? init : new window.Headers(init)
}
export function _method__fetch(ctx__fetch):string {
return (ctx__fetch.method || 'GET').toUpperCase()
}
export async function throw__response__fetch(response) {
log(`${logPrefix}|throw__response__fetch`)
const error_message = await response.text()
throw__error({
status__http: response.status,
error_message,
})
}
export async function waitfor__backoff__fibonacci(fn, delay = 500) {