react-native-simple-networking
Advanced tools
Comparing version
@@ -16,4 +16,7 @@ "use strict"; | ||
const axios_1 = __importDefault(require("axios")); | ||
axios_1.default.defaults.headers.common = { | ||
'Content-Type': "application/json" | ||
}; | ||
function createAxiosClient({ axiosConfig, refresh, attemptRefreshOnStatusCodes = [401, 498], authStore, }) { | ||
const config = Object.assign(Object.assign({}, axiosConfig), { headers: Object.assign({ 'Content-Type': 'application/json' }, axiosConfig === null || axiosConfig === void 0 ? void 0 : axiosConfig.headers) }); | ||
const config = axiosConfig ? axiosConfig : {}; | ||
const axiosClient = axios_1.default.create(config); | ||
@@ -31,3 +34,3 @@ // Authentication Interceptor - Automatically add the token to request header if it exists and the user is logged in. | ||
console.log(`REQUEST - ${config.method} ${config.url}`); | ||
logReport(config); | ||
logReport(config, ''); | ||
return config; | ||
@@ -90,3 +93,3 @@ }); | ||
}); | ||
function logReport(config) { | ||
function logReport(config, name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -108,3 +111,3 @@ const report = {}; | ||
report.baseUrl = config.baseURL; | ||
console.log("Report: "); | ||
console.log(name + " Report: "); | ||
console.log(JSON.stringify(report, null, 4)); | ||
@@ -111,0 +114,0 @@ }); |
{ | ||
"name": "react-native-simple-networking", | ||
"version": "1.0.16", | ||
"version": "1.0.17", | ||
"description": "This is a package that implements authentication state using zustand tied to axios interceptors in order to automatically add an 'authorization' header to all requests any time a request is sent with the created axios client. It also provides some basic request logging. The package will attempt to refresh any time an access token is expired, stalling all requests any time a token refresh is going on. ", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
import axios, { AxiosError, AxiosRequestConfig } from "axios"; | ||
import { UseBoundStore, StoreApi } from "zustand"; | ||
import { CreateAuthStoreResult } from "./createAuthenticationStore"; | ||
axios.defaults.headers.common = { | ||
'Content-Type': "application/json" | ||
} | ||
@@ -19,11 +22,6 @@ export type AxiosOptions = { | ||
}) { | ||
const config: AxiosRequestConfig = { | ||
...axiosConfig, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
...axiosConfig?.headers | ||
}, | ||
} | ||
const config: AxiosRequestConfig = axiosConfig?axiosConfig:{}; | ||
const axiosClient = axios.create(config) | ||
const axiosClient = axios.create(config); | ||
@@ -45,3 +43,3 @@ // Authentication Interceptor - Automatically add the token to request header if it exists and the user is logged in. | ||
console.log(`REQUEST - ${config.method} ${config.url}`); | ||
logReport(config); | ||
logReport(config, ''); | ||
return config; | ||
@@ -110,3 +108,3 @@ }) | ||
async function logReport(config: AxiosRequestConfig) { | ||
async function logReport(config: AxiosRequestConfig, name: string,) { | ||
const report: any = {}; | ||
@@ -126,3 +124,3 @@ if (config.data) { | ||
report.baseUrl = config.baseURL; | ||
console.log("Report: ") | ||
console.log(name + " Report: ") | ||
console.log(JSON.stringify(report, null, 4)) | ||
@@ -129,0 +127,0 @@ } |
22316
-0.3%