Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/graphql / src / bootstrapper / api / proxyPathConfigs.ts
Size: Mime:
import express from 'express'
import { Cookie, CookieJar } from 'tough-cookie'
import { isArray, isObj, isTrue, isEmpty } from 'uxui-modules/exotic'
import { clientDomain, clientVersion } from './ENV'
import { cookieConfig } from './cookieConfig'
import { getStreamDataAccessObjType } from './STREAMDAO'

// const cookieJar = new CookieJar()
// @TODO change the base url & config ^
// @NOTE we would want the proxies if we want the production
// so when we merge into master or when we have the flag
// then test on real api responses - best of both
// if (!ENV_TEST || ENV_API_PROD) {
//   // change the config
// }

const apiConfig = { clientDomain, clientVersion }

const https = 'https'
const baseUrlPrefix = `${https}://${clientDomain}/skavastream`

const getBaseTargetURL = (objectDAO, callType) => {
  /* @TODO Sort this out properly as proxy is broken  */
  let targetUrl = ''

  const version = objectDAO.clientVersion
    ? objectDAO.clientVersion
    : apiConfig.clientVersion

  if (objectDAO.isProxyAPI) {
    // console.log('isProxy API')
    /* @TODO @Anto - Hardcoded for now will move it to config*/
    targetUrl = 'http://encrypt-stg.skavaone.com/apiadmin/remote/skavakeystore/getKeyForToken'
  } else if (callType === 'GET') {
    targetUrl = `${baseUrlPrefix}/${objectDAO.type}/${version}/${
      objectDAO.partner
    }`
  } else {
    targetUrl = `${baseUrlPrefix}/${objectDAO.type}/${version}/${
      objectDAO.partner
    }`
  }

  console.log({ objectDAO, callType, targetUrl })

  return targetUrl
}

const getURL = (route, callType) => {
  const type = route.replace('/', '')
  const objectDAO = getStreamDataAccessObjType(type)
  const target = getBaseTargetURL(objectDAO, callType)
  return target
}

const endpoints = [
  '/productlist',
  '/category',
  '/product',
  '/viewbag',
  '/getlists',
  '/profile',
  '/search',
  '/reviews',
  '/getstores',
  '/register',
  '/createlist',
  '/additem',
  '/deleteitem',
  '/getitems',
  '/login',
  '/profile',
  '/logout',
  '/setshippingaddress/update',
  '/setpaymentmethod',
  '/deletecard',
  '/submitreview',
  '/resetpassword',
  '/orderdetails',
  '/submitorder/return',
  '/submitorder/cancel',
  '/addtobag',
  '/deletefrombag',
  '/estimate',
  '/updatebag',
  '/updateshippingmethods',
  '/payment',
  '/submitorder',
  '/setshippingaddress',
  '/searchsuggestion',
  '/updatepassword',
  '/getsecurityquestion',
  '/suspendcart',
  '/user',
  '/getCatalog',
  '/getPages',
  '/getKeyForToken',
  '/loyalty',
  '/checkoutauth',
]
const callDetails = {
  '/productlist': 'GET',
  '/category': 'GET',
  '/product': 'GET',
  '/viewbag': 'GET',
  '/getlists': 'POST',
  '/profile': 'POST',
  '/search': 'GET',
  '/reviews': 'POST',
  '/submitreview': 'POST',
  '/getstores': 'POST',
  '/register': 'POST',
  '/additem': 'POST',
  '/deleteitem': 'POST',
  '/getitems': 'POST',
  '/login': 'POST',
  '/logout': 'POST',
  '/setshippingaddress/update': 'POST',
  '/setpaymentmethod': 'POST',
  '/deletecard': 'POST',
  '/resetpassword': 'POST',
  '/orderdetails': 'POST',
  '/submitorder/return': 'POST',
  '/submitorder/cancel': 'POST',
  '/addtobag': 'POST',
  '/deletefrombag': 'POST',
  '/estimate': 'POST',
  '/updatebag': 'POST',
  '/updateshippingmethods': 'POST',
  '/payment': 'POST',
  '/submitorder': 'POST',
  '/setshippingaddress': 'POST',
  '/searchsuggestion': 'GET',
  '/suspendcart': 'POST',
  '/user': 'GET',
  '/getCatalog': 'GET',
  '/getPages': 'GET',
  '/getKeyForToken': 'GET',
  '/loyalty': 'POST',
  '/checkoutauth': 'POST',
}

Object.freeze(endpoints)
Object.freeze(callDetails)

export {
  apiConfig,
  https,
  baseUrlPrefix,
  getBaseTargetURL,
  getURL,
  endpoints,
  callDetails,
}