UNPKG

cluedin-widget

Version:

This project contains all the pages needed for browsing entities and searching them. The aim is to replace the CluedIn.Webapp project with this one when all the pages ( including the Admin page ) will be ported to REACT.

101 lines (73 loc) 1.98 kB
import config from '../config'; var agent = require('superagent-promise')(require('superagent'), Promise); const defaultHeaders = { }; const getDefaultHeaders = () => { return { Authorization: 'Bearer ' + config.getCurrentToken(), 'Accept': 'application/json', }; }; function isObject(obj) { return Object(obj) === obj; } export const authWithoutCreds = function (method, url) { url = config.url.auth + url; return agent(method, url); }; export const authRequest = function (method, url) { url = config.url.auth + url; return agent(method, url).set(getDefaultHeaders()); }; export const apiRequest = function (method, url, data) { url = config.url.api + url; return agent(method, url).set(getDefaultHeaders()).then(function (resp) { if (resp) { resp.__token = config.getCurrentToken(); } return resp; }); }; const setHeaders = function (field, value) { if (isObject(field)) { for (var key in field) { this.set(key, field[key]); } return this; } defaultHeaders[field] = value; return this; }; export const frontApiRequest = function (method, url, data) { url = config.url.app + url; var agentCall = agent(method, url); if (data) { agentCall = agentCall.send(data); } return agentCall.withCredentials().set(getDefaultHeaders()); }; export const appFrontApiRequest = function (method, url, data) { url = config.url.mainApp + url; var agentCall = agent(method, url); if (data) { agentCall = agentCall.send(data); } return agentCall.withCredentials().set(getDefaultHeaders()); }; export const rawRequest = function (method, url, data) { return agent(method, url).set(getDefaultHeaders()).then(function (resp) { if (resp) { resp.__token = config.token; } return resp; }); }; authRequest.set = setHeaders; apiRequest.set = setHeaders; export default { authRequest, apiRequest, frontApiRequest, rawRequest, appFrontApiRequest, };