Repository URL to install this package:
|
Version:
2.0.12 ▾
|
import express from 'express'
import { Cookie, CookieJar } from 'tough-cookie'
import { isArray, isObj, isTrue, isEmpty } from 'exotic'
import * as config from '../bootstrapper/api/config'
import { getStreamDataAccessObjType } from '../bootstrapper/api/STREAMDAO'
import { API_LAYER_ENV, STREAM_API_LAYER } from '../bootstrapper/api/config'
// 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 { clientDomain, clientVersion, cookieConfig } = config
const apiConfig = { clientDomain, clientVersion }
const https = 'http'
const baseUrlPrefix =
STREAM_API_LAYER !== API_LAYER_ENV
? `${https}://${clientDomain}`
: `${https}://${clientDomain}/skavastream`
const getBaseTargetURL = objectDAO => {
/* @TODO Sort this out properly as proxy is broken */
let targetUrl = ''
console.log('API_LAYER_ENV', API_LAYER_ENV)
const version = objectDAO.clientVersion
? objectDAO.clientVersion
: apiConfig.clientVersion
if (objectDAO.isAbsoluteUrl) {
targetUrl = objectDAO['absoluteUrl']
} else if (STREAM_API_LAYER !== API_LAYER_ENV) {
const orchestrationService = objectDAO.orchestrationService
? objectDAO.orchestrationService
: ''
const orchestrationServiceType = objectDAO.orchestrationServiceType
? objectDAO.orchestrationServiceType
: ''
const pathParams = objectDAO.pathParams ? objectDAO.pathParams : ''
targetUrl = `${baseUrlPrefix}${orchestrationService}${orchestrationServiceType}${pathParams}`
} else {
targetUrl = `${baseUrlPrefix}/${objectDAO.type}/${version}/${
objectDAO.partner
}`
}
console.log('transformproxy', targetUrl)
return targetUrl || 'https://@@FAIL'
}
const getURL = (route, callType) => {
// const type = route.replace('/', '')
if (route) {
// const type = route.substring(route.lastIndexOf("/") + 1, route.length)
//Todo @anto this needs to be optimized in better way
//spliting api's like /api/payment/add and reusing the same stream dao
const types = route.split('api/')[1]
const type = types ? types.split('/')[0] : ''
const objectDAO = getStreamDataAccessObjType(types)
let apiObjectDAO = objectDAO
if (!objectDAO.type) {
apiObjectDAO = getStreamDataAccessObjType(type)
}
if (!isEmpty(type)) {
const target = getBaseTargetURL(apiObjectDAO)
let targetUrl = `${target}/${types}`
if (STREAM_API_LAYER !== API_LAYER_ENV) {
targetUrl = `${target}`
}
return targetUrl
} else {
return route
}
} else {
return route
}
}
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',
'/token/create',
'/resetByMailUrl',
'/validateresetpassword',
'/resetpasswordbysecurityquestion',
'/resetpasswordbyemail',
'/useraddresses',
'/useractivation',
'/accountinvite',
'/accountprofile',
'/accountregister',
]
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': 'DELETE',
'/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',
'/token/create': 'POST',
'/resetByMailUrl': 'POST',
'/validateresetpassword': 'POST',
'/resetpasswordbysecurityquestion': 'POST',
'/resetpasswordbyemail': 'POST',
'/useractivation': 'PATCH',
'/accountinvite': 'PATCH',
'/accountprofile': 'GET',
'/accountregister': 'POST',
}
Object.freeze(endpoints)
Object.freeze(callDetails)
export {
apiConfig,
https,
baseUrlPrefix,
getBaseTargetURL,
getURL,
endpoints,
callDetails,
}