11cb0ef41Sopenharmony_ciconst { FetchError, Headers, Request, Response } = require('minipass-fetch')
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst configureOptions = require('./options.js')
41cb0ef41Sopenharmony_ciconst fetch = require('./fetch.js')
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst makeFetchHappen = (url, opts) => {
71cb0ef41Sopenharmony_ci  const options = configureOptions(opts)
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci  const request = new Request(url, options)
101cb0ef41Sopenharmony_ci  return fetch(request, options)
111cb0ef41Sopenharmony_ci}
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cimakeFetchHappen.defaults = (defaultUrl, defaultOptions = {}, wrappedFetch = makeFetchHappen) => {
141cb0ef41Sopenharmony_ci  if (typeof defaultUrl === 'object') {
151cb0ef41Sopenharmony_ci    defaultOptions = defaultUrl
161cb0ef41Sopenharmony_ci    defaultUrl = null
171cb0ef41Sopenharmony_ci  }
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  const defaultedFetch = (url, options = {}) => {
201cb0ef41Sopenharmony_ci    const finalUrl = url || defaultUrl
211cb0ef41Sopenharmony_ci    const finalOptions = {
221cb0ef41Sopenharmony_ci      ...defaultOptions,
231cb0ef41Sopenharmony_ci      ...options,
241cb0ef41Sopenharmony_ci      headers: {
251cb0ef41Sopenharmony_ci        ...defaultOptions.headers,
261cb0ef41Sopenharmony_ci        ...options.headers,
271cb0ef41Sopenharmony_ci      },
281cb0ef41Sopenharmony_ci    }
291cb0ef41Sopenharmony_ci    return wrappedFetch(finalUrl, finalOptions)
301cb0ef41Sopenharmony_ci  }
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  defaultedFetch.defaults = (defaultUrl1, defaultOptions1 = {}) =>
331cb0ef41Sopenharmony_ci    makeFetchHappen.defaults(defaultUrl1, defaultOptions1, defaultedFetch)
341cb0ef41Sopenharmony_ci  return defaultedFetch
351cb0ef41Sopenharmony_ci}
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_cimodule.exports = makeFetchHappen
381cb0ef41Sopenharmony_cimodule.exports.FetchError = FetchError
391cb0ef41Sopenharmony_cimodule.exports.Headers = Headers
401cb0ef41Sopenharmony_cimodule.exports.Request = Request
411cb0ef41Sopenharmony_cimodule.exports.Response = Response
42