@fctc/edu-logic-lib 1.0.3 → 1.0.5
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/index.d.mts +1294 -23
- package/dist/index.d.ts +1294 -23
- package/package.json +96 -96
- package/dist/base-model-type-DvO53Lwi.d.mts +0 -7
- package/dist/base-model-type-DvO53Lwi.d.ts +0 -7
- package/dist/config.d.mts +0 -15
- package/dist/config.d.ts +0 -15
- package/dist/config.js +0 -262
- package/dist/config.mjs +0 -256
- package/dist/constants.d.mts +0 -120
- package/dist/constants.d.ts +0 -120
- package/dist/constants.js +0 -154
- package/dist/constants.mjs +0 -141
- package/dist/context-type-D5XefoL-.d.mts +0 -8
- package/dist/context-type-D5XefoL-.d.ts +0 -8
- package/dist/environment.d.mts +0 -37
- package/dist/environment.d.ts +0 -37
- package/dist/environment.js +0 -849
- package/dist/environment.mjs +0 -841
- package/dist/hooks.d.mts +0 -218
- package/dist/hooks.d.ts +0 -218
- package/dist/hooks.js +0 -4865
- package/dist/hooks.mjs +0 -4814
- package/dist/index-C_nK1Mii.d.mts +0 -19
- package/dist/index-C_nK1Mii.d.ts +0 -19
- package/dist/models.d.mts +0 -35
- package/dist/models.d.ts +0 -35
- package/dist/models.js +0 -3225
- package/dist/models.mjs +0 -3217
- package/dist/provider.d.mts +0 -16
- package/dist/provider.d.ts +0 -16
- package/dist/provider.js +0 -3232
- package/dist/provider.mjs +0 -3224
- package/dist/services.d.mts +0 -160
- package/dist/services.d.ts +0 -160
- package/dist/services.js +0 -4045
- package/dist/services.mjs +0 -4032
- package/dist/store.d.mts +0 -505
- package/dist/store.d.ts +0 -505
- package/dist/store.js +0 -582
- package/dist/store.mjs +0 -519
- package/dist/types.d.mts +0 -12
- package/dist/types.d.ts +0 -12
- package/dist/types.js +0 -2
- package/dist/types.mjs +0 -1
- package/dist/use-get-selection-DFh6sc49.d.mts +0 -26
- package/dist/use-get-selection-DFh6sc49.d.ts +0 -26
- package/dist/utils.d.mts +0 -52
- package/dist/utils.d.ts +0 -52
- package/dist/utils.js +0 -2360
- package/dist/utils.mjs +0 -2344
- package/dist/view-type-BTzRpkT7.d.mts +0 -106
- package/dist/view-type-BTzRpkT7.d.ts +0 -106
package/package.json
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@fctc/edu-logic-lib",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"types": "dist/index.d.ts",
|
|
5
|
-
"main": "dist/index.cjs",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"registry": "https://registry.npmjs.org/",
|
|
9
|
-
"access": "public"
|
|
10
|
-
},
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"types": "./dist/index.d.ts",
|
|
14
|
-
"import": "./dist/index.mjs",
|
|
15
|
-
"require": "./dist/index.cjs"
|
|
16
|
-
},
|
|
17
|
-
"./config": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/
|
|
20
|
-
"require": "./dist/
|
|
21
|
-
},
|
|
22
|
-
"./constants": {
|
|
23
|
-
"types": "./dist/
|
|
24
|
-
"import": "./dist/
|
|
25
|
-
"require": "./dist/
|
|
26
|
-
},
|
|
27
|
-
"./environment": {
|
|
28
|
-
"types": "./dist/
|
|
29
|
-
"import": "./dist/
|
|
30
|
-
"require": "./dist/
|
|
31
|
-
},
|
|
32
|
-
"./hooks": {
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"import": "./dist/
|
|
35
|
-
"require": "./dist/
|
|
36
|
-
},
|
|
37
|
-
"./provider": {
|
|
38
|
-
"types": "./dist/
|
|
39
|
-
"import": "./dist/
|
|
40
|
-
"require": "./dist/
|
|
41
|
-
},
|
|
42
|
-
"./services": {
|
|
43
|
-
"types": "./dist/
|
|
44
|
-
"import": "./dist/
|
|
45
|
-
"require": "./dist/
|
|
46
|
-
},
|
|
47
|
-
"./store": {
|
|
48
|
-
"types": "./dist/
|
|
49
|
-
"import": "./dist/
|
|
50
|
-
"require": "./dist/
|
|
51
|
-
},
|
|
52
|
-
"./utils": {
|
|
53
|
-
"types": "./dist/
|
|
54
|
-
"import": "./dist/
|
|
55
|
-
"require": "./dist/
|
|
56
|
-
},
|
|
57
|
-
"./types": {
|
|
58
|
-
"types": "./dist/
|
|
59
|
-
"import": "./dist/
|
|
60
|
-
"require": "./dist/
|
|
61
|
-
},
|
|
62
|
-
"./models": {
|
|
63
|
-
"types": "./dist/
|
|
64
|
-
"import": "./dist/
|
|
65
|
-
"require": "./dist/
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
"files": [
|
|
69
|
-
"dist"
|
|
70
|
-
],
|
|
71
|
-
"scripts": {
|
|
72
|
-
"build": "tsup",
|
|
73
|
-
"prepublishOnly": "yarn build",
|
|
74
|
-
"test": "jest"
|
|
75
|
-
},
|
|
76
|
-
"peerDependencies": {
|
|
77
|
-
"react": "^18.0.0",
|
|
78
|
-
"@tanstack/react-query": "^5.83.0",
|
|
79
|
-
"react-redux": "^9.2.0",
|
|
80
|
-
"@reduxjs/toolkit": "^2.8.2"
|
|
81
|
-
},
|
|
82
|
-
"dependencies": {
|
|
83
|
-
"axios": "^1.11.0"
|
|
84
|
-
},
|
|
85
|
-
"devDependencies": {
|
|
86
|
-
"@types/react": "^18.3.1",
|
|
87
|
-
"jest": "^29.7.0",
|
|
88
|
-
"react": "18.0.0",
|
|
89
|
-
"react-redux": "^9.2.0",
|
|
90
|
-
"@reduxjs/toolkit": "^2.8.2",
|
|
91
|
-
"@tanstack/react-query": "^5.83.0",
|
|
92
|
-
"tsup": "^8.0.0",
|
|
93
|
-
"typescript": "^5.8.2"
|
|
94
|
-
},
|
|
95
|
-
"packageManager": "yarn@1.22.0"
|
|
96
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@fctc/edu-logic-lib",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"types": "dist/index.d.ts",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"registry": "https://registry.npmjs.org/",
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./config": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"require": "./dist/index.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./constants": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.mjs",
|
|
25
|
+
"require": "./dist/index.cjs"
|
|
26
|
+
},
|
|
27
|
+
"./environment": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.mjs",
|
|
30
|
+
"require": "./dist/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"./hooks": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.mjs",
|
|
35
|
+
"require": "./dist/index.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./provider": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"import": "./dist/index.mjs",
|
|
40
|
+
"require": "./dist/index.cjs"
|
|
41
|
+
},
|
|
42
|
+
"./services": {
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"import": "./dist/index.mjs",
|
|
45
|
+
"require": "./dist/index.cjs"
|
|
46
|
+
},
|
|
47
|
+
"./store": {
|
|
48
|
+
"types": "./dist/index.d.ts",
|
|
49
|
+
"import": "./dist/index.mjs",
|
|
50
|
+
"require": "./dist/index.cjs"
|
|
51
|
+
},
|
|
52
|
+
"./utils": {
|
|
53
|
+
"types": "./dist/index.d.ts",
|
|
54
|
+
"import": "./dist/index.mjs",
|
|
55
|
+
"require": "./dist/index.cjs"
|
|
56
|
+
},
|
|
57
|
+
"./types": {
|
|
58
|
+
"types": "./dist/index.d.ts",
|
|
59
|
+
"import": "./dist/index.mjs",
|
|
60
|
+
"require": "./dist/index.cjs"
|
|
61
|
+
},
|
|
62
|
+
"./models": {
|
|
63
|
+
"types": "./dist/index.d.ts",
|
|
64
|
+
"import": "./dist/index.mjs",
|
|
65
|
+
"require": "./dist/index.cjs"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"files": [
|
|
69
|
+
"dist"
|
|
70
|
+
],
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "tsup",
|
|
73
|
+
"prepublishOnly": "yarn build",
|
|
74
|
+
"test": "jest"
|
|
75
|
+
},
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"react": "^18.0.0",
|
|
78
|
+
"@tanstack/react-query": "^5.83.0",
|
|
79
|
+
"react-redux": "^9.2.0",
|
|
80
|
+
"@reduxjs/toolkit": "^2.8.2"
|
|
81
|
+
},
|
|
82
|
+
"dependencies": {
|
|
83
|
+
"axios": "^1.11.0"
|
|
84
|
+
},
|
|
85
|
+
"devDependencies": {
|
|
86
|
+
"@types/react": "^18.3.1",
|
|
87
|
+
"jest": "^29.7.0",
|
|
88
|
+
"react": "18.0.0",
|
|
89
|
+
"react-redux": "^9.2.0",
|
|
90
|
+
"@reduxjs/toolkit": "^2.8.2",
|
|
91
|
+
"@tanstack/react-query": "^5.83.0",
|
|
92
|
+
"tsup": "^8.0.0",
|
|
93
|
+
"typescript": "^5.8.2"
|
|
94
|
+
},
|
|
95
|
+
"packageManager": "yarn@1.22.0"
|
|
96
|
+
}
|
package/dist/config.d.mts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { EnvStore } from './environment.mjs';
|
|
2
|
-
import '@reduxjs/toolkit';
|
|
3
|
-
|
|
4
|
-
declare const axiosClient: {
|
|
5
|
-
init(config: EnvStore): {
|
|
6
|
-
get: (url: string, headers: any) => Promise<any>;
|
|
7
|
-
post: (url: string, body: any, headers: any) => Promise<any>;
|
|
8
|
-
post_excel: (url: string, body: any, headers: any) => Promise<any>;
|
|
9
|
-
put: (url: string, body: any, headers: any) => Promise<any>;
|
|
10
|
-
patch: (url: string, body: any) => Promise<any>;
|
|
11
|
-
delete: (url: string, body: any) => Promise<any>;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export { axiosClient };
|
package/dist/config.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { EnvStore } from './environment.js';
|
|
2
|
-
import '@reduxjs/toolkit';
|
|
3
|
-
|
|
4
|
-
declare const axiosClient: {
|
|
5
|
-
init(config: EnvStore): {
|
|
6
|
-
get: (url: string, headers: any) => Promise<any>;
|
|
7
|
-
post: (url: string, body: any, headers: any) => Promise<any>;
|
|
8
|
-
post_excel: (url: string, body: any, headers: any) => Promise<any>;
|
|
9
|
-
put: (url: string, body: any, headers: any) => Promise<any>;
|
|
10
|
-
patch: (url: string, body: any) => Promise<any>;
|
|
11
|
-
delete: (url: string, body: any) => Promise<any>;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export { axiosClient };
|
package/dist/config.js
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var axios = require('axios');
|
|
4
|
-
|
|
5
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
-
|
|
7
|
-
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
8
|
-
|
|
9
|
-
// src/config/axios-client.ts
|
|
10
|
-
var MAINT_KEY = "MAINTENANCE_ACTIVE";
|
|
11
|
-
var MAINT_AT = "MAINTENANCE_AT";
|
|
12
|
-
var MAINT_LAST_PATH = "MAINTENANCE_LAST_PATH";
|
|
13
|
-
var hasRedirectedToMaintenance = false;
|
|
14
|
-
function setMaintenanceFlags() {
|
|
15
|
-
if (typeof window === "undefined") return;
|
|
16
|
-
const { pathname, search } = window.location;
|
|
17
|
-
const lastPath = pathname + (search || "");
|
|
18
|
-
if (pathname !== "/maintenance" && !window.localStorage.getItem(MAINT_LAST_PATH)) {
|
|
19
|
-
window.localStorage.setItem(MAINT_LAST_PATH, lastPath);
|
|
20
|
-
}
|
|
21
|
-
window.localStorage.setItem(MAINT_KEY, "true");
|
|
22
|
-
window.localStorage.setItem(MAINT_AT, String(Date.now()));
|
|
23
|
-
}
|
|
24
|
-
async function clearMaintenanceAndExit(getToken, opts) {
|
|
25
|
-
if (typeof window === "undefined") return;
|
|
26
|
-
const forceLogin = opts?.forceLogin === true;
|
|
27
|
-
const clearTokenOnForce = opts?.clearTokenOnForce !== false;
|
|
28
|
-
window.localStorage.removeItem(MAINT_KEY);
|
|
29
|
-
window.localStorage.removeItem(MAINT_AT);
|
|
30
|
-
const lastPath = window.localStorage.getItem(MAINT_LAST_PATH);
|
|
31
|
-
window.localStorage.removeItem(MAINT_LAST_PATH);
|
|
32
|
-
try {
|
|
33
|
-
if (forceLogin) {
|
|
34
|
-
if (clearTokenOnForce) {
|
|
35
|
-
try {
|
|
36
|
-
await opts?.clearToken?.();
|
|
37
|
-
} catch {
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
window.location.replace("/login");
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const token = await getToken();
|
|
44
|
-
if (token) {
|
|
45
|
-
const target = lastPath && lastPath !== "/maintenance" ? lastPath : "/";
|
|
46
|
-
window.location.replace(target);
|
|
47
|
-
} else {
|
|
48
|
-
window.location.replace("/login");
|
|
49
|
-
}
|
|
50
|
-
} catch {
|
|
51
|
-
window.location.replace("/login");
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
var axiosClient = {
|
|
55
|
-
init(config) {
|
|
56
|
-
const localStorage = config.localStorageUtils;
|
|
57
|
-
const sessionStorage = config.sessionStorageUtils;
|
|
58
|
-
const db = config.db;
|
|
59
|
-
let isRefreshing = false;
|
|
60
|
-
let failedQueue = [];
|
|
61
|
-
const processQueue = (error, token = null) => {
|
|
62
|
-
failedQueue?.forEach((prom) => {
|
|
63
|
-
if (error) {
|
|
64
|
-
prom.reject(error);
|
|
65
|
-
} else {
|
|
66
|
-
prom.resolve(token);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
failedQueue = [];
|
|
70
|
-
};
|
|
71
|
-
const instance = axios__default.default.create({
|
|
72
|
-
adapter: axios__default.default.defaults.adapter,
|
|
73
|
-
baseURL: config.baseUrl,
|
|
74
|
-
timeout: 5e4,
|
|
75
|
-
paramsSerializer: (params) => new URLSearchParams(params).toString()
|
|
76
|
-
});
|
|
77
|
-
if (typeof window !== "undefined") {
|
|
78
|
-
const isMaint = window.localStorage.getItem(MAINT_KEY) === "true";
|
|
79
|
-
const onMaintenancePage = window.location.pathname === "/maintenance";
|
|
80
|
-
if (isMaint && !onMaintenancePage) {
|
|
81
|
-
hasRedirectedToMaintenance = true;
|
|
82
|
-
window.location.replace("/maintenance");
|
|
83
|
-
}
|
|
84
|
-
if (isMaint && onMaintenancePage) {
|
|
85
|
-
const healthUrl = config.healthUrl || `${(config.baseUrl || "").replace(/\/+$/, "")}/health`;
|
|
86
|
-
(async () => {
|
|
87
|
-
try {
|
|
88
|
-
await axios__default.default.get(healthUrl, { timeout: 8e3 });
|
|
89
|
-
await clearMaintenanceAndExit(() => localStorage.getAccessToken(), {
|
|
90
|
-
forceLogin: true,
|
|
91
|
-
clearTokenOnForce: true,
|
|
92
|
-
clearToken: () => localStorage.clearToken()
|
|
93
|
-
});
|
|
94
|
-
} catch {
|
|
95
|
-
}
|
|
96
|
-
})();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
instance.interceptors.request.use(
|
|
100
|
-
async (configReq) => {
|
|
101
|
-
const token = await localStorage.getAccessToken();
|
|
102
|
-
if (token) {
|
|
103
|
-
configReq.headers["Authorization"] = "Bearer " + token;
|
|
104
|
-
}
|
|
105
|
-
return configReq;
|
|
106
|
-
},
|
|
107
|
-
(error) => Promise.reject(error)
|
|
108
|
-
);
|
|
109
|
-
instance.interceptors.response.use(
|
|
110
|
-
(response) => {
|
|
111
|
-
if (typeof window !== "undefined") {
|
|
112
|
-
const isMaint = window.localStorage.getItem(MAINT_KEY) === "true";
|
|
113
|
-
const onMaintenancePage = window.location.pathname === "/maintenance";
|
|
114
|
-
if (isMaint && onMaintenancePage) {
|
|
115
|
-
(async () => {
|
|
116
|
-
await clearMaintenanceAndExit(
|
|
117
|
-
() => localStorage.getAccessToken(),
|
|
118
|
-
{
|
|
119
|
-
forceLogin: true,
|
|
120
|
-
clearTokenOnForce: true,
|
|
121
|
-
clearToken: () => localStorage.clearToken()
|
|
122
|
-
}
|
|
123
|
-
);
|
|
124
|
-
})();
|
|
125
|
-
} else if (isMaint) {
|
|
126
|
-
window.localStorage.removeItem(MAINT_KEY);
|
|
127
|
-
window.localStorage.removeItem(MAINT_AT);
|
|
128
|
-
window.localStorage.removeItem(MAINT_LAST_PATH);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return handleResponse(response);
|
|
132
|
-
},
|
|
133
|
-
async (error) => {
|
|
134
|
-
const status = error?.response?.status;
|
|
135
|
-
if (status === 503) {
|
|
136
|
-
if (typeof window !== "undefined") {
|
|
137
|
-
setMaintenanceFlags();
|
|
138
|
-
if (!hasRedirectedToMaintenance && window.location.pathname !== "/maintenance") {
|
|
139
|
-
hasRedirectedToMaintenance = true;
|
|
140
|
-
window.location.replace("/maintenance");
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return Promise.reject({
|
|
144
|
-
code: 503,
|
|
145
|
-
message: "SERVICE_UNAVAILABLE",
|
|
146
|
-
original: error?.response?.data
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
const handleError = async (err) => {
|
|
150
|
-
if (!err.response) {
|
|
151
|
-
return err;
|
|
152
|
-
}
|
|
153
|
-
const { data } = err.response;
|
|
154
|
-
if (data && data.code === 400 && ["invalid_grant"].includes(data.data?.error)) {
|
|
155
|
-
await clearAuthToken();
|
|
156
|
-
}
|
|
157
|
-
return data;
|
|
158
|
-
};
|
|
159
|
-
const originalRequest = error.config;
|
|
160
|
-
if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401].includes(
|
|
161
|
-
error.response.data.code
|
|
162
|
-
)) {
|
|
163
|
-
if (isRefreshing) {
|
|
164
|
-
return new Promise(function(resolve, reject) {
|
|
165
|
-
failedQueue.push({ resolve, reject });
|
|
166
|
-
}).then((token) => {
|
|
167
|
-
originalRequest.headers["Authorization"] = "Bearer " + token;
|
|
168
|
-
return instance.request(originalRequest);
|
|
169
|
-
}).catch(async (err) => {
|
|
170
|
-
if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
|
|
171
|
-
await clearAuthToken();
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
const browserSession = await sessionStorage.getBrowserSession();
|
|
176
|
-
const refreshToken = await localStorage.getRefreshToken();
|
|
177
|
-
const accessTokenExp = await localStorage.getAccessToken();
|
|
178
|
-
isRefreshing = true;
|
|
179
|
-
if (!refreshToken && (!browserSession || browserSession == "unActive")) {
|
|
180
|
-
await clearAuthToken();
|
|
181
|
-
} else {
|
|
182
|
-
const payload = Object.fromEntries(
|
|
183
|
-
Object.entries({
|
|
184
|
-
refresh_token: refreshToken,
|
|
185
|
-
grant_type: "refresh_token",
|
|
186
|
-
client_id: config.config.clientId,
|
|
187
|
-
client_secret: config.config.clientSecret
|
|
188
|
-
}).filter(([_, value]) => !!value)
|
|
189
|
-
);
|
|
190
|
-
return new Promise(function(resolve) {
|
|
191
|
-
axios__default.default.post(
|
|
192
|
-
`${config.baseUrl}${"/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
|
|
193
|
-
payload,
|
|
194
|
-
{
|
|
195
|
-
headers: {
|
|
196
|
-
"Content-Type": "multipart/form-data",
|
|
197
|
-
Authorization: `Bearer ${accessTokenExp}`
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
).then(async (res) => {
|
|
201
|
-
const data = res.data;
|
|
202
|
-
await localStorage.setToken(data.access_token);
|
|
203
|
-
await localStorage.setRefreshToken(data.refresh_token);
|
|
204
|
-
axios__default.default.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
|
|
205
|
-
originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
|
|
206
|
-
processQueue(null, data.access_token);
|
|
207
|
-
resolve(instance.request(originalRequest));
|
|
208
|
-
}).catch(async (err) => {
|
|
209
|
-
if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_BAD_REQUEST")) {
|
|
210
|
-
await clearAuthToken();
|
|
211
|
-
}
|
|
212
|
-
if (err && err.response) {
|
|
213
|
-
const { error_code } = err.response?.data || {};
|
|
214
|
-
if (error_code === "AUTHEN_FAIL") {
|
|
215
|
-
await clearAuthToken();
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
processQueue(err, null);
|
|
219
|
-
}).finally(() => {
|
|
220
|
-
isRefreshing = false;
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return Promise.reject(await handleError(error));
|
|
226
|
-
}
|
|
227
|
-
);
|
|
228
|
-
const handleResponse = (res) => {
|
|
229
|
-
if (res && res.data) {
|
|
230
|
-
return res.data;
|
|
231
|
-
}
|
|
232
|
-
return res;
|
|
233
|
-
};
|
|
234
|
-
const clearAuthToken = async () => {
|
|
235
|
-
await localStorage.clearToken();
|
|
236
|
-
if (typeof window !== "undefined") {
|
|
237
|
-
window.location.href = `/login`;
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
function formatUrl(url, db2) {
|
|
241
|
-
return url + (db2 ? "?db=" + db2 : "");
|
|
242
|
-
}
|
|
243
|
-
const responseBody = (response) => response;
|
|
244
|
-
const requests = {
|
|
245
|
-
get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
|
|
246
|
-
post: (url, body, headers) => instance.post(formatUrl(url, db), body, { headers }).then(responseBody),
|
|
247
|
-
post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
|
|
248
|
-
responseType: "arraybuffer",
|
|
249
|
-
headers: {
|
|
250
|
-
"Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
|
|
251
|
-
Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
252
|
-
}
|
|
253
|
-
}).then(responseBody),
|
|
254
|
-
put: (url, body, headers) => instance.put(formatUrl(url, db), body, headers).then(responseBody),
|
|
255
|
-
patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
|
|
256
|
-
delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
|
|
257
|
-
};
|
|
258
|
-
return requests;
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
exports.axiosClient = axiosClient;
|