2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import axios from 'axios';
22 import {GlobalExtConstants} from './GlobalExtConstants.js';
24 const commonApi = (settings, path, httpMethodType, reqPayload, stubPath, overrideDomain, specialCase, additionalHeaders, noProxy) => {
25 let BASE_URL = GlobalExtConstants.BASE_URL;
27 //enter proxy details here for local
35 let APERTURE_SERVICE = JSON.parse(sessionStorage.getItem(GlobalExtConstants.ENVIRONMENT + 'APERTURE_SERVICE'));
37 SWITCH_URL = overrideDomain + '/';
38 if(settings.ISTABULAR){
39 SWITCH_URL+= settings.TABULAR + '/'
40 + settings.PREFIX + '/'
41 + settings.APERTURE + '/'
42 + settings.TABULARVERSION + '/'
47 }else if(APERTURE_SERVICE && (settings.ISAPERTURE !== undefined)){
48 let baseURL = (settings.NODESERVER) ? 'https://'+ settings.NODESERVER : BASE_URL;
49 SWITCH_URL = baseURL + '/';
51 SWITCH_URL += settings.PROXY + '/';
53 SWITCH_URL += settings.PREFIX + '/'
54 + settings.APERTURE + '/';
55 if(settings.ISAPERTURE && settings.APERTURE_SERVICENAME !== undefined){
56 SWITCH_URL += settings.VERSION + '/'
57 + settings.APERTURE_SERVICENAME;
58 }else if(settings.ISAPERTURE){
59 SWITCH_URL += settings.VERSION + '/';
62 }else if(settings.NODESERVER){
63 SWITCH_URL = 'https://'
64 + settings.NODESERVER + '/';
66 SWITCH_URL += settings.PROXY + '/';
68 SWITCH_URL += settings.PREFIX + '/';
70 SWITCH_URL += specialCase + '/';
72 SWITCH_URL += settings.VERSION + '/'
75 SWITCH_URL = BASE_URL + '/';
77 SWITCH_URL += settings.PROXY + '/';
79 SWITCH_URL += settings.PREFIX + '/';
81 SWITCH_URL += specialCase + '/';
83 SWITCH_URL += settings.VERSION + '/'
86 console.log('Making call to the backend >>>>>>>>>>>', SWITCH_URL);
88 var headers = {'Content-Type' : 'application/json','Access-Control-Allow-Origin' : '*','X-FromAppId':'AAI-UI', 'X-TransactionId' : 'AAI-UI', 'Accept':'application/json'};
89 if(additionalHeaders){
90 for(var i = 0; i < additionalHeaders.length; i++){
91 if(additionalHeaders[i].name && additionalHeaders[i].value){
92 headers[additionalHeaders[i].name] = additionalHeaders[i].value;
94 console.log("CommonAPIService :: Additional headers passed in are not in teh proper format: "+ JSON.stringify(additionalHeaders));
98 console.log("HEADER VALUES: "+ headers);
99 if(settings.USESTUBS){
100 return new Promise((resolve, reject) => {
101 var responseObj = {};
102 responseObj.data = require('app/assets/stubs/' + stubPath + '.json');
103 responseObj.status = 200;
104 responseObj.headers = [];
105 if(responseObj.data && responseObj.data.results){
106 responseObj.headers['total-results'] = Object.keys(responseObj.data.results).length;
107 resolve(responseObj);
108 }else if(responseObj.data && ['BYOQPersonalQueries','BYOQCommunityQueries','BYOQPublicQueries','ConvertQueryToTree','SingleTransactionEdit'].indexOf(stubPath) > -1 ){
109 resolve(responseObj);
110 }else if(responseObj.data){
111 responseObj.headers['total-results'] = 0;
112 reject(responseObj.data);
117 }else if (['PUT','PATCH','DELETE','POST'].indexOf(httpMethodType) > -1 && reqPayload !== null) {
118 return axios({ method: httpMethodType,
123 if(settings.NODESERVER){
124 return axios.get(SWITCH_URL, proxyConfig);
126 return axios.get(SWITCH_URL);
131 export default commonApi;