How to use the cross-fetch function in cross-fetch

To help you get started, we’ve selected a few cross-fetch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github opencollective / backyourstack / src / lib / github.js View on Github external
branch: branch,
    path,
    withAccessToken: !!accessToken,
  });

  if (repo.private === true) {
    const params = { owner: repo.owner.login, repo: repo.name, path: path };
    // https://octokit.github.io/rest.js/#api-Repos-getContent
    return fetchWithOctokit('repos.getContents', params, accessToken).then(
      getContent,
    );
  }

  const relativeUrl = `/${repo.owner.login}/${repo.name}/${branch}/${path}`;
  logger.verbose(`Fetching file from public repo ${relativeUrl}`);
  return fetch(`${baseRawUrl}${relativeUrl}`).then(response => {
    if (response.status === 200) {
      return response.text();
    }
    throw new Error(`Can't fetch ${path} from ${relativeUrl}.`);
  });
}
github inaturalist / inaturalist / app / webpack / observations / uploader / models / util.js View on Github external
static isOnline( callback ) {
    // temporary until we have a ping API
    fetch( "/pages/about", {
      method: "head",
      mode: "no-cors",
      cache: "no-store" } ).
    then( ( ) => callback( true ) ).
    catch( ( ) => callback( false ) );
  }
github OriginProtocol / origin / packages / graphql / src / mutations / _txHelper.js View on Github external
async function fetchGasPrice() {
  const res = await fetch(GAS_STATION_URL)
  if (res.status !== 200) {
    throw new Error(`Fetch returned code ${res.status}`)
  }
  const jason = await res.json()
  if (typeof jason[GAS_PRICE_KEY] !== 'undefined') {
    // values come from EGS as tenths of gwei
    return jason[GAS_PRICE_KEY] * 1e8
  }
  throw new Error(`Gas key of ${GAS_PRICE_KEY} is unavailable`)
}
github neo-one-suite / neo-one / packages / neo-one-editor / src / manager / managePackages.ts View on Github external
mergeScanLatest(async (_acc, dependencies) => {
        const resolvedDependencies: ResolvedDependencies = await fetch(RESOLVE_URL, {
          method: 'POST',
          body: JSON.stringify(dependencies),
          mode: 'no-cors',
          headers,
        }).then(async (res) => {
          if (!res.ok) {
            throw new FetchError(RESOLVE_URL, res.status, res.statusText);
          }

          return res.json();
        });

        await handleDependencies(fs, queue, resolvedDependencies);
      }),
      retryBackoff(1000),
github diegomura / react-pdf / src / utils / image.js View on Github external
const fetchRemoteFile = async (uri, options) => {
  const response = await fetch(uri, options);

  const buffer = await (response.buffer
    ? response.buffer()
    : response.arrayBuffer());

  return buffer.constructor.name === 'Buffer' ? buffer : Buffer.from(buffer);
};
github neo-one-suite / neo-one / packages / neo-one-server-plugin-network / src / node / NEOONENodeAdapter.ts View on Github external
private async checkRPC(rpcPath: string): Promise {
    try {
      const response = await fetch(this.getAddress(rpcPath));

      return response.ok;
    } catch (error) {
      if (error.code !== 'ECONNREFUSED') {
        this.monitor.withData({ [this.monitor.labels.HTTP_PATH]: rpcPath }).logError({
          name: 'http_client_request',
          message: 'Failed to check RPC.',
          error,
        });
      }

      return false;
    }
  }
github cezerin / client / src / webstoreClient.js View on Github external
static authorize = (email, adminUrl) => {
		const config = {
			method: 'post',
			headers: {
				'Content-Type': 'application/json'
			},
			body: JSON.stringify({ email, admin_url: adminUrl })
		};

		return fetch('https://api.cezerin.com/v1/account/authorize', config).then(
			RestClient.returnStatusAndJson
		);
	};
}
github filips123 / ZeroFrameJS / src / index.js View on Github external
async _getWrapperKey () {
    const siteUrl = 'http' + (this.instance.secure ? 's' : '') + '://' + this.instance.host + ':' + this.instance.port + '/' + this.site

    const wrapperRequest = await fetch(siteUrl, { headers: { Accept: 'text/html' } })
    const wrapperBody = await wrapperRequest.text()

    const wrapperKey = wrapperBody.match(/wrapper_key = "(.*?)"/)[1]

    return wrapperKey
  }
github zilpay / zil-pay / extension / controllers / services / network / index.js View on Github external
async checkProvider() {
    /**
     * Call the options requests to node URL.
     */
    try {
      await fetch(this.provider);
      this.status = true;
    } catch(err) {
      this.status = false;
    }

    return this.status;
  }
github ahodges9 / LedFx / ledfx / frontend / actions / schemas.js View on Github external
return dispatch => {
    dispatch(requestSchemas());
    return fetch(`${apiUrl}/schema`)
      .then(response => response.json())
      .then(json => dispatch(receiveSchemas(json)));
  };
}