How to use superagent-proxy - 10 common examples

To help you get started, we’ve selected a few superagent-proxy 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 pubnub / javascript / src / networking / modules / node.js View on Github external
/* @flow */

import superagent from 'superagent';
import superagentProxy from 'superagent-proxy';
import AgentKeepAlive from 'agentkeepalive';

let keepAliveAgent: (AgentKeepAlive | AgentKeepAlive.HttpsAgent) = null;
let keepAliveSecureAgent: (AgentKeepAlive | AgentKeepAlive.HttpsAgent) = null;

superagentProxy(superagent);

export function proxy(superagentConstruct: superagent) {
  return superagentConstruct.proxy(this._config.proxy);
}

export function keepAlive(superagentConstruct: superagent) {
  let agent = this._config.secure ? keepAliveSecureAgent : keepAliveAgent;
  if (agent === null) {
    let AgentClass = this._config.secure ? AgentKeepAlive.HttpsAgent : AgentKeepAlive;
    agent = new AgentClass(this._config.keepAliveSettings);
    if (this._config.secure) {
      keepAliveSecureAgent = agent;
    } else {
      keepAliveAgent = agent;
    }
  }
github SAPConversationalAI / SDK-NodeJS / src / apis / request / Request.js View on Github external
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'

import constants from '../constants'
import { Response, RecastError } from '../resources'

const agent = superagentPromise(superagentProxy(superagent), Promise)

export default class Request {

  constructor (token, language) {
    this.token = token
    this.language = language
  }

  textRequest = async (text, options = {}) => {
    const token = options.token || this.token
    const proxy = options.proxy
    const data = { text, language: options.language || this.language }
    if (!token) { throw new RecastError('Parameter token is missing') }

    try {
      const request = agent('POST', constants.REQUEST_ENDPOINT)
github SAPConversationalAI / SDK-NodeJS / src / apis / request / converse.js View on Github external
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'

import constants from '../constants'
import { Conversation, RecastError } from '../resources'

const agent = superagentPromise(superagentProxy(superagent), Promise)

export default class Converse {

  constructor (token, language) {
    this.token = token
    this.language = language
  }

  textConverse = async (text, options = {}) => {
    const token = options.token || this.token
    const proxy = options.proxy
    const data = {
      text,
      language: options.language || this.language,
      conversation_token: options.conversationToken,
      memory: options.memory,
github SAPConversationalAI / SDK-NodeJS / src / apis / build / index.js View on Github external
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'

const agent = superagentPromise(superagentProxy(superagent), Promise)

import constants from '../constants'

export default class Build {

  constructor (token, language) {
    this.token = token
    this.language = language
  }

  dialog = (message, options = {}, memory = null, log_level = 'info') => {
    const token = options.token || this.token
    const proxy = options.proxy
    const data = {
      message,
      conversation_id: options.conversationId,
github SAPConversationalAI / SDK-NodeJS / src / apis / connect / index.js View on Github external
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'

const agent = superagentPromise(superagentProxy(superagent), Promise)

import constants from '../constants'
import { Message } from '../resources'

export default class Connect {

  constructor (token) {
    this.token = token
  }

  handleMessage = (req, res, onMessageReceived) => {
    if (typeof res.status === 'function') {
      res.status(200).send()
    } else {
      res.status = 200
    }
github SAPConversationalAI / SDK-NodeJS / src / apis / resources / conversation.js View on Github external
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'

import constants from '../constants'

const agent = superagentPromise(superagentProxy(superagent), Promise)

export default class Conversation {

  constructor ({ conversation_token, next_actions, ...response }) {
    for (const key in response) {
      this[key] = response[key]
    }

    this.nextActions = next_actions
    this.conversationToken = conversation_token
  }

  /**
   * Returns the first reply if there is one
   * @returns {String}: this first reply or null
   */
github SAPConversationalAI / SDK-NodeJS / src / apis / connect / Connect.js View on Github external
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'

const agent = superagentPromise(superagentProxy(superagent), Promise)

import constants from '../constants'
import { Message } from '../resources'

export default class Connect {

  constructor (token) {
    this.token = token
  }

  handleMessage = (req, res, onMessageReceived) => {
    if (typeof res.status === 'function') {
      res.status(200).send()
    } else {
      res.status = 200
    }
github SAPConversationalAI / SDK-NodeJS / src / apis / resources / message.js View on Github external
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'

import constants from '../constants'

const agent = superagentPromise(superagentProxy(superagent), Promise)

export default class Message {

  constructor (body, sapcaiToken) {
    for (const key in body) {
      this[key] = body[key]
    }

    this.content = body.message.attachment.content
    this.type = body.message.attachment.type
    this.conversationId = body.message.conversation
    this.sapcaiToken = sapcaiToken
    this._messageStack = []
  }

  addReply = (replies) => this._messageStack = this._messageStack.concat(replies)
github SAPConversationalAI / SDK-NodeJS / src / apis / train / index.js View on Github external
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'

import constants from '../constants'
import { SapcaiError } from '../resources'

import Bots from './bots'
import Entities from './entities'
import Gazettes from './gazettes'
import Intents from './intents'
import Logs from './logs'

const agent = superagentPromise(superagentProxy(superagent), Promise)

export default class Train {

  constructor (token, language, version, userSlug, botSlug) {
    if (typeof userSlug !== 'string' || typeof botSlug !== 'string') {
      throw new SapcaiError('Train client must be initiated with a user slug and a bot slug')
    }

    this.token = token
    this.language = language
    this.userSlug = userSlug
    this.botSlug = botSlug
    this.botVersion = version

    this.bots = new Bots(this)
    this.entities = new Entities(this)
github SAPConversationalAI / SDK-NodeJS / src / apis / request / index.js View on Github external
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'

import constants from '../constants'
import { Conversation, Response, SapcaiError } from '../resources'

const agent = superagentPromise(superagentProxy(superagent), Promise)

export default class Request {

  constructor (token, language) {
    this.token = token
    this.language = language
  }

  /*
   * /request (with text string)
   */
  analyseText = async (text, options = {}) => {
    const token = options.token || this.token
    const proxy = options.proxy
    const data = { text, language: options.language || this.language }
    if (!token) { throw new SapcaiError('Parameter token is missing') }

superagent-proxy

`Request#proxy(uri)` superagent extension

MIT
Latest version published 3 years ago

Package Health Score

59 / 100
Full package analysis

Popular superagent-proxy functions