@servicetitan/ajax-handlers
Advanced tools
Comparing version 17.2.0 to 17.2.1
@@ -68,12 +68,14 @@ "use strict"; | ||
const absoluteUrlRegex = /^(?:[a-z]+:)?\/\//i; | ||
config.headers.common = { | ||
'Content-Type': 'application/json;charset=UTF-8', | ||
'Accept': 'application/json', | ||
}; | ||
if (config.url && !absoluteUrlRegex.test(config.url)) { | ||
config.headers.common['X-Requested-With'] = 'XMLHttpRequest'; | ||
const CSRFTokenName = 'X-CSRF-Token'; | ||
const token = js_cookie_1.default.get(CSRFTokenName); | ||
if (token) { | ||
config.headers.common[CSRFTokenName] = token; | ||
if (config.headers) { | ||
config.headers = { | ||
'Content-Type': 'application/json;charset=UTF-8', | ||
'Accept': 'application/json', | ||
}; | ||
if (config.url && !absoluteUrlRegex.test(config.url)) { | ||
config.headers['X-Requested-With'] = 'XMLHttpRequest'; | ||
const CSRFTokenName = 'X-CSRF-Token'; | ||
const token = js_cookie_1.default.get(CSRFTokenName); | ||
if (token) { | ||
config.headers[CSRFTokenName] = token; | ||
} | ||
} | ||
@@ -80,0 +82,0 @@ } |
{ | ||
"name": "@servicetitan/ajax-handlers", | ||
"version": "17.2.0", | ||
"version": "17.2.1", | ||
"description": "", | ||
@@ -20,6 +20,6 @@ "repository": { | ||
"devDependencies": { | ||
"@servicetitan/react-ioc": "^17.2.0", | ||
"@servicetitan/react-ioc": "^17.2.1", | ||
"@types/jquery": "~2.0.57", | ||
"@types/js-cookie": "~2.2.7", | ||
"axios": "~0.21.2", | ||
"@types/js-cookie": "~3.0.0", | ||
"axios": "~0.23.0", | ||
"jquery": "~2.1.4", | ||
@@ -30,3 +30,3 @@ "react": "~17.0.2" | ||
"@servicetitan/react-ioc": "^14.0.0", | ||
"axios": "~0.21.2", | ||
"axios": "~0.23.0", | ||
"jquery": "~2.1.4", | ||
@@ -41,3 +41,3 @@ "react": "~17.0.2" | ||
}, | ||
"gitHead": "4a3151bd82763b1a8d4407bcabc675bb17d6a629" | ||
"gitHead": "d68b581cd1bc979b26a56e465f1b0a5fbca02df9" | ||
} |
@@ -1,2 +0,2 @@ | ||
import axios, { AxiosTransformer } from 'axios'; | ||
import axios, { AxiosRequestTransformer } from 'axios'; | ||
import Cookies from 'js-cookie'; | ||
@@ -36,3 +36,3 @@ | ||
export const initAjaxHandlersCommon = () => { | ||
const transformer: AxiosTransformer = data => { | ||
const transformer: AxiosRequestTransformer = data => { | ||
if (typeof data === 'string') { | ||
@@ -75,14 +75,16 @@ return dateFromString(data); | ||
config.headers.common = { | ||
'Content-Type': 'application/json;charset=UTF-8', | ||
'Accept': 'application/json', | ||
}; | ||
if (config.headers) { | ||
config.headers = { | ||
'Content-Type': 'application/json;charset=UTF-8', | ||
'Accept': 'application/json', | ||
}; | ||
if (config.url && !absoluteUrlRegex.test(config.url)) { | ||
config.headers.common['X-Requested-With'] = 'XMLHttpRequest'; | ||
if (config.url && !absoluteUrlRegex.test(config.url)) { | ||
config.headers['X-Requested-With'] = 'XMLHttpRequest'; | ||
const CSRFTokenName = 'X-CSRF-Token'; | ||
const token = Cookies.get(CSRFTokenName); | ||
if (token) { | ||
config.headers.common[CSRFTokenName] = token; | ||
const CSRFTokenName = 'X-CSRF-Token'; | ||
const token = Cookies.get(CSRFTokenName); | ||
if (token) { | ||
config.headers[CSRFTokenName] = token; | ||
} | ||
} | ||
@@ -89,0 +91,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
53383
963