How to use the node-fetch.Promise function in node-fetch

To help you get started, we’ve selected a few node-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 fortunejs / fortune / test / integration / middlewares.js View on Github external
import Test from 'tape'
import connect from 'connect'
import express from 'express'
import fetch from 'node-fetch'
import Fortune from '../../lib'
import generateApp from './generate_app'
import Serializer from '../../lib/serializer'


// Set promise polyfill for old versions of Node.
fetch.Promise = Promise

const port = 1337
const mediaType = 'application/json'

class DefaultSerializer extends Serializer {
  processResponse (context) {
    const { payload } = context.response
    context.response.payload = new Buffer(JSON.stringify(payload))
    return context
  }
}

DefaultSerializer.id = mediaType

const frameworks = [
  { name: 'express', fn: express },
github crownstone / CrownstoneApp / helpers / clearCloud.js View on Github external
const fetch = require('node-fetch');
const Promise = require("promise");


/**
 *
 * ALL KEYS IN HERE ARE ONLY USED FOR TESTING PURPOSES. THERE IS NO PRIVATE DATE HERE.
 *
 * @type {{Accept: string, Content-Type: string}}
 */

// fucking fetch lib uses its own promises!
fetch.Promise = Promise;

//alex
let token = 'kuikqcrDYZBvIABLwM68HE5JhDgXdrSXfIdcj92mqsL5FZtH9wAdFP0qMT4fU55x';
let userId = '5747122cfb25ed03000bdc70';

//anne
// let token = 'FrEAgEDUZCIksrdM5GkZCIIEmCg0Z4gbuoI57YsURvT8CGhZcq1HB8JgcPAs83mD';
// let userId = '57cef12aa54fcf0300c5074c';

let defaultHeaders = {
  'Accept': 'application/json',
  'Content-Type': 'application/json'
};
let handleInitialReply = (response) => {
  STATUS = response.status;
  if (response &&
github kidtsunami / fetch-salesforce / build / lib / fetchRequest.js View on Github external
"use strict";
var fetch = require('node-fetch');
var Promise = require('bluebird');
fetch.Promise = Promise;
function fetchJSON(requestURL, requestOptions) {
    console.info('Fetching: ' + requestURL);
    console.info(requestOptions);
    return fetch(requestURL, requestOptions)
        .then(function (response) { return response.json(); })
        .then(function (response) {
        if (response.error) {
            var fetchJSONException = {
                fetchURL: requestURL,
                requestOptions: requestOptions,
                response: response
            };
            console.error(fetchJSONException);
            throw fetchJSONException;
        }
        else {
github yai333 / React-Chat-App-using-AWS-API-Gateway-Websocket-and-Serverless-Framework / auth / handler.js View on Github external
"use strict";

const AWS = require("aws-sdk");
const Bluebird = require("bluebird");
const jose = require("node-jose");
const fetch = require("node-fetch");
fetch.Promise = Bluebird;

module.exports.authorizerFunc = async (event, context, callback) => {
  const keys_url =
    "https://cognito-idp.ap-southeast-2.amazonaws.com/USER_POOL_ID/.well-known/jwks.json";
  const {
    queryStringParameters: { token },
    methodArn
  } = event;

  const app_client_id = APP_CLIENT_ID;
  if (!token) return context.fail("Unauthorized");
  const sections = token.split(".");
  let authHeader = jose.util.base64url.decode(sections[0]);
  authHeader = JSON.parse(authHeader);
  const kid = authHeader.kid;
  const rawRes = await fetch(keys_url);
github moleculerjs / moleculer / src / tracing / exporters / zipkin.js View on Github external
"use strict";

const _ 					= require("lodash");
const Promise 				= require("bluebird");
const fetch 				= require("node-fetch");
const BaseTraceExporter 	= require("./base");

fetch.Promise = Promise;

/**
 * Trace Exporter for Zipkin.
 *
 * API v2: https://zipkin.io/zipkin-api/#/
 * API v1: https://zipkin.io/pages/data_model.html
 *
 * Running Zipkin in Docker:
 *
 * 	 docker run -d -p 9411:9411 --name=zipkin openzipkin/zipkin
 *
 * @class ZipkinTraceExporter
 */
class ZipkinTraceExporter extends BaseTraceExporter {

	/**
github dfsq / json-server-init / src / create / write-json.js View on Github external
var fs = require('fs'),
    Promise = require('promise'),
    fetch = require('node-fetch');

if (!fetch.Promise) {
    fetch.Promise = Promise;
}

/**
 * Writes generated JSON into file.
 * @param dbName {String} Name of the file to create.
 * @param schema {Object} Populated object of collections.
 * @return {Promise}
 */
function writeJSON(dbName, schema) {

    var baseUrl = 'http://www.filltext.com/?',
        promises = [],
        collection;

    for (collection in schema) {
github dfsq / json-server-init / src / create / write-json.js View on Github external
var fs = require('fs'),
    Promise = require('promise'),
    fetch = require('node-fetch');

if (!fetch.Promise) {
    fetch.Promise = Promise;
}

/**
 * Writes generated JSON into file.
 * @param dbName {String} Name of the file to create.
 * @param schema {Object} Populated object of collections.
 * @return {Promise}
 */
function writeJSON(dbName, schema) {

    var baseUrl = 'http://www.filltext.com/?',
        promises = [],
        collection;

    for (collection in schema) {
github Dwolla / dwolla-v2-node / src / dwolla / Token.js View on Github external
var fetch = require("node-fetch");
var formurlencoded = require("form-urlencoded").default;
var rejectEmptyKeys = require("../util/rejectEmptyKeys");
var isFormData = require("../util/isFormData");
var assign = require("lodash/assign");
var Promise = require("bluebird");

fetch.Promise = Promise;

var Token = function(client, opts) {
  this.client = client;
  this.access_token = opts.access_token;
  this.refresh_token = opts.refresh_token;
  this.expires_in = opts.expires_in;
  this.scope = opts.scope;
  this.account_id = opts.account_id;
};

function getHeaders(token, moreHeaders) {
  return assign(
    {
      Authorization: ["Bearer", token.access_token].join(" "),
      Accept: "application/vnd.dwolla.v1.hal+json",
      "User-Agent": require("./userAgent")
github phylogeny-explorer / explorer / client / src / core / fetch / fetch.server.js View on Github external
import Promise from 'bluebird';
import fetch, { Request, Headers, Response } from 'node-fetch';
import { adminApiHost } from '../../config';

fetch.Promise = Promise;
Response.Promise = Promise;

function localUrl(url) {
  if (url.startsWith('http')) {
    return url;
  }

  return `//${adminApiHost}${url}`;
}

function localFetch(url, options) {
  return fetch(localUrl(url), options);
}

export { localFetch as default, Request, Headers, Response };
github moleculerjs / moleculer / src / metrics / reporters / datadog.js View on Github external
* moleculer
 * Copyright (c) 2019 MoleculerJS (https://github.com/moleculerjs/moleculer)
 * MIT Licensed
 */

"use strict";

const BaseReporter = require("./base");
const _ = require("lodash");
const os = require("os");
const Promise = require("bluebird");
const fetch = require("node-fetch");
const { MoleculerError } = require("../../errors");
const METRIC = require("../constants");

fetch.Promise = Promise;

const BASE_URL = "https://api.datadoghq.com/api/";

/**
 * Datadog reporter for Moleculer.
 *
 * 		https://www.datadoghq.com/
 *
 */
class DatadogReporter extends BaseReporter {

	/**
	 * Constructor of DatadogReporters
	 * @param {Object} opts
	 * @memberof DatadogReporter
	 */