@vritti/quantum-ui 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/axios.js +28 -7
- package/dist/axios.js.map +1 -1
- package/dist/index.d.ts +10 -7
- package/package.json +1 -1
package/dist/axios.js
CHANGED
|
@@ -15,15 +15,33 @@ const defaultConfig = {
|
|
|
15
15
|
},
|
|
16
16
|
auth: {
|
|
17
17
|
tokenHeaderName: "Authorization",
|
|
18
|
-
tokenPrefix: "Bearer"
|
|
18
|
+
tokenPrefix: "Bearer",
|
|
19
|
+
tokenEndpoint: "cloud-api/auth/token",
|
|
20
|
+
refreshEndpoint: "cloud-api/auth/refresh",
|
|
21
|
+
sessionRecoveryEnabled: true
|
|
19
22
|
}
|
|
20
23
|
};
|
|
21
|
-
|
|
24
|
+
const GLOBAL_CONFIG_KEY = "__QUANTUM_UI_CONFIG__";
|
|
25
|
+
function getGlobalConfig() {
|
|
26
|
+
if (typeof window !== "undefined") {
|
|
27
|
+
const globalWindow = window;
|
|
28
|
+
if (!globalWindow[GLOBAL_CONFIG_KEY]) {
|
|
29
|
+
globalWindow[GLOBAL_CONFIG_KEY] = { ...defaultConfig };
|
|
30
|
+
}
|
|
31
|
+
return globalWindow[GLOBAL_CONFIG_KEY] ?? { ...defaultConfig };
|
|
32
|
+
}
|
|
33
|
+
return { ...defaultConfig };
|
|
34
|
+
}
|
|
35
|
+
function setGlobalConfig(config) {
|
|
36
|
+
if (typeof window !== "undefined") {
|
|
37
|
+
window[GLOBAL_CONFIG_KEY] = config;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
22
40
|
function defineConfig(config) {
|
|
23
41
|
return config;
|
|
24
42
|
}
|
|
25
43
|
function configureQuantumUI(userConfig) {
|
|
26
|
-
|
|
44
|
+
const newConfig = {
|
|
27
45
|
csrf: {
|
|
28
46
|
...defaultConfig.csrf,
|
|
29
47
|
...userConfig.csrf || {}
|
|
@@ -41,12 +59,13 @@ function configureQuantumUI(userConfig) {
|
|
|
41
59
|
...userConfig.auth || {}
|
|
42
60
|
}
|
|
43
61
|
};
|
|
62
|
+
setGlobalConfig(newConfig);
|
|
44
63
|
}
|
|
45
64
|
function getConfig() {
|
|
46
|
-
return
|
|
65
|
+
return getGlobalConfig();
|
|
47
66
|
}
|
|
48
67
|
function resetConfig() {
|
|
49
|
-
|
|
68
|
+
setGlobalConfig({ ...defaultConfig });
|
|
50
69
|
}
|
|
51
70
|
|
|
52
71
|
function bind(fn, thisArg) {
|
|
@@ -3919,7 +3938,7 @@ const clearCsrfToken = () => {
|
|
|
3919
3938
|
async function recoverToken() {
|
|
3920
3939
|
const config = getConfig();
|
|
3921
3940
|
try {
|
|
3922
|
-
const response = await axios$1.get(
|
|
3941
|
+
const response = await axios$1.get(config.auth.tokenEndpoint, {
|
|
3923
3942
|
baseURL: config.axios.baseURL,
|
|
3924
3943
|
withCredentials: true,
|
|
3925
3944
|
timeout: config.axios.timeout
|
|
@@ -3935,6 +3954,8 @@ async function recoverToken() {
|
|
|
3935
3954
|
}
|
|
3936
3955
|
}
|
|
3937
3956
|
async function recoverTokenIfNeeded() {
|
|
3957
|
+
const config = getConfig();
|
|
3958
|
+
if (!config.auth.sessionRecoveryEnabled) return true;
|
|
3938
3959
|
if (accessToken) return true;
|
|
3939
3960
|
if (sessionRecoveryPromise) {
|
|
3940
3961
|
return sessionRecoveryPromise;
|
|
@@ -3962,7 +3983,7 @@ function scheduleTokenRefresh(expiresIn) {
|
|
|
3962
3983
|
const config = getConfig();
|
|
3963
3984
|
try {
|
|
3964
3985
|
const response = await axios$1.post(
|
|
3965
|
-
|
|
3986
|
+
config.auth.refreshEndpoint,
|
|
3966
3987
|
{},
|
|
3967
3988
|
{
|
|
3968
3989
|
baseURL: config.axios.baseURL,
|