@fctc/interface-logic 1.7.7 → 1.7.8
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/configs.d.mts +4 -4
- package/dist/configs.d.ts +4 -4
- package/dist/configs.js +15 -12
- package/dist/configs.mjs +15 -12
- package/dist/environment.d.mts +56 -35
- package/dist/environment.d.ts +56 -35
- package/dist/environment.js +1915 -1851
- package/dist/environment.mjs +1913 -1850
- package/dist/hooks.d.mts +1 -6
- package/dist/hooks.d.ts +1 -6
- package/dist/hooks.js +2150 -1889
- package/dist/hooks.mjs +2123 -1861
- package/dist/provider.js +310 -18
- package/dist/provider.mjs +310 -18
- package/dist/services.d.mts +0 -1
- package/dist/services.d.ts +0 -1
- package/dist/services.js +2099 -1822
- package/dist/services.mjs +2099 -1822
- package/dist/store.d.mts +28 -112
- package/dist/store.d.ts +28 -112
- package/dist/store.js +6 -12
- package/dist/store.mjs +6 -12
- package/package.json +81 -81
package/dist/provider.js
CHANGED
|
@@ -81,16 +81,10 @@ var breadcrums_slice_default = breadcrumbsSlice.reducer;
|
|
|
81
81
|
var import_toolkit2 = require("@reduxjs/toolkit");
|
|
82
82
|
var initialState2 = {
|
|
83
83
|
baseUrl: "",
|
|
84
|
+
requests: null,
|
|
84
85
|
companies: [],
|
|
85
86
|
user: {},
|
|
86
|
-
|
|
87
|
-
refreshTokenEndpoint: "",
|
|
88
|
-
config: {
|
|
89
|
-
grantType: "",
|
|
90
|
-
clientId: "",
|
|
91
|
-
clientSecret: "",
|
|
92
|
-
redirectUri: ""
|
|
93
|
-
},
|
|
87
|
+
config: null,
|
|
94
88
|
envFile: null,
|
|
95
89
|
defaultCompany: {
|
|
96
90
|
id: null,
|
|
@@ -2807,19 +2801,315 @@ function matchDomain(record, domain) {
|
|
|
2807
2801
|
|
|
2808
2802
|
// src/utils/function.ts
|
|
2809
2803
|
var import_react = require("react");
|
|
2804
|
+
var updateTokenParamInOriginalRequest = (originalRequest, newAccessToken) => {
|
|
2805
|
+
if (!originalRequest.data) return originalRequest.data;
|
|
2806
|
+
if (typeof originalRequest.data === "string") {
|
|
2807
|
+
try {
|
|
2808
|
+
const parsedData = JSON.parse(originalRequest.data);
|
|
2809
|
+
if (parsedData.with_context && typeof parsedData.with_context === "object") {
|
|
2810
|
+
parsedData.with_context.token = newAccessToken;
|
|
2811
|
+
}
|
|
2812
|
+
return JSON.stringify(parsedData);
|
|
2813
|
+
} catch (e) {
|
|
2814
|
+
console.warn("Failed to parse originalRequest.data", e);
|
|
2815
|
+
return originalRequest.data;
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
if (typeof originalRequest.data === "object" && originalRequest.data.with_context) {
|
|
2819
|
+
originalRequest.data.with_context.token = newAccessToken;
|
|
2820
|
+
}
|
|
2821
|
+
return originalRequest.data;
|
|
2822
|
+
};
|
|
2823
|
+
|
|
2824
|
+
// src/utils/storage/local-storage.ts
|
|
2825
|
+
var localStorageUtils = () => {
|
|
2826
|
+
const setToken = async (access_token) => {
|
|
2827
|
+
localStorage.setItem("accessToken", access_token);
|
|
2828
|
+
};
|
|
2829
|
+
const setRefreshToken = async (refresh_token) => {
|
|
2830
|
+
localStorage.setItem("refreshToken", refresh_token);
|
|
2831
|
+
};
|
|
2832
|
+
const getAccessToken = async () => {
|
|
2833
|
+
return localStorage.getItem("accessToken");
|
|
2834
|
+
};
|
|
2835
|
+
const getRefreshToken = async () => {
|
|
2836
|
+
return localStorage.getItem("refreshToken");
|
|
2837
|
+
};
|
|
2838
|
+
const clearToken = async () => {
|
|
2839
|
+
localStorage.removeItem("accessToken");
|
|
2840
|
+
localStorage.removeItem("refreshToken");
|
|
2841
|
+
};
|
|
2842
|
+
return {
|
|
2843
|
+
setToken,
|
|
2844
|
+
setRefreshToken,
|
|
2845
|
+
getAccessToken,
|
|
2846
|
+
getRefreshToken,
|
|
2847
|
+
clearToken
|
|
2848
|
+
};
|
|
2849
|
+
};
|
|
2850
|
+
|
|
2851
|
+
// src/utils/storage/session-storage.ts
|
|
2852
|
+
var sessionStorageUtils = () => {
|
|
2853
|
+
const getBrowserSession = async () => {
|
|
2854
|
+
return sessionStorage.getItem("browserSession");
|
|
2855
|
+
};
|
|
2856
|
+
return {
|
|
2857
|
+
getBrowserSession
|
|
2858
|
+
};
|
|
2859
|
+
};
|
|
2860
|
+
|
|
2861
|
+
// src/configs/axios-client.ts
|
|
2862
|
+
var axiosClient = {
|
|
2863
|
+
init(config) {
|
|
2864
|
+
const localStorage2 = config?.localStorageUtils ?? localStorageUtils();
|
|
2865
|
+
const sessionStorage2 = config?.sessionStorageUtils ?? sessionStorageUtils();
|
|
2866
|
+
const db = config?.db;
|
|
2867
|
+
let isRefreshing = false;
|
|
2868
|
+
let failedQueue = [];
|
|
2869
|
+
const processQueue = (error, token = null) => {
|
|
2870
|
+
failedQueue?.forEach((prom) => {
|
|
2871
|
+
if (error) {
|
|
2872
|
+
prom.reject(error);
|
|
2873
|
+
} else {
|
|
2874
|
+
prom.resolve(token);
|
|
2875
|
+
}
|
|
2876
|
+
});
|
|
2877
|
+
failedQueue = [];
|
|
2878
|
+
};
|
|
2879
|
+
const instance = import_axios.default.create({
|
|
2880
|
+
adapter: import_axios.default.defaults.adapter,
|
|
2881
|
+
baseURL: config.baseUrl,
|
|
2882
|
+
timeout: 5e4,
|
|
2883
|
+
paramsSerializer: (params) => new URLSearchParams(params).toString()
|
|
2884
|
+
});
|
|
2885
|
+
instance.interceptors.request.use(
|
|
2886
|
+
async (config2) => {
|
|
2887
|
+
const useRefreshToken = config2.useRefreshToken;
|
|
2888
|
+
const token = useRefreshToken ? await localStorage2.getRefreshToken() : await localStorage2.getAccessToken();
|
|
2889
|
+
if (token) {
|
|
2890
|
+
config2.headers["Authorization"] = "Bearer " + token;
|
|
2891
|
+
}
|
|
2892
|
+
return config2;
|
|
2893
|
+
},
|
|
2894
|
+
(error) => {
|
|
2895
|
+
Promise.reject(error);
|
|
2896
|
+
}
|
|
2897
|
+
);
|
|
2898
|
+
instance.interceptors.response.use(
|
|
2899
|
+
(response) => {
|
|
2900
|
+
return handleResponse(response);
|
|
2901
|
+
},
|
|
2902
|
+
async (error) => {
|
|
2903
|
+
const handleError3 = async (error2) => {
|
|
2904
|
+
if (!error2.response) {
|
|
2905
|
+
return error2;
|
|
2906
|
+
}
|
|
2907
|
+
const { data } = error2.response;
|
|
2908
|
+
if (data && data.code === 400 && ["invalid_grant"].includes(data.data?.error)) {
|
|
2909
|
+
await clearAuthToken();
|
|
2910
|
+
}
|
|
2911
|
+
return data;
|
|
2912
|
+
};
|
|
2913
|
+
const originalRequest = error.config;
|
|
2914
|
+
if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401, "ERR_2FA_006"].includes(
|
|
2915
|
+
error.response.data.code
|
|
2916
|
+
)) {
|
|
2917
|
+
if (isRefreshing) {
|
|
2918
|
+
return new Promise(function(resolve, reject) {
|
|
2919
|
+
failedQueue.push({ resolve, reject });
|
|
2920
|
+
}).then((token) => {
|
|
2921
|
+
originalRequest.headers["Authorization"] = "Bearer " + token;
|
|
2922
|
+
originalRequest.data = updateTokenParamInOriginalRequest(
|
|
2923
|
+
originalRequest,
|
|
2924
|
+
token
|
|
2925
|
+
);
|
|
2926
|
+
return instance.request(originalRequest);
|
|
2927
|
+
}).catch(async (err) => {
|
|
2928
|
+
if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
|
|
2929
|
+
await clearAuthToken();
|
|
2930
|
+
}
|
|
2931
|
+
});
|
|
2932
|
+
}
|
|
2933
|
+
const browserSession = await sessionStorage2.getBrowserSession();
|
|
2934
|
+
const refreshToken = await localStorage2.getRefreshToken();
|
|
2935
|
+
const accessTokenExp = await localStorage2.getAccessToken();
|
|
2936
|
+
isRefreshing = true;
|
|
2937
|
+
if (!refreshToken && (!browserSession || browserSession == "unActive")) {
|
|
2938
|
+
await clearAuthToken();
|
|
2939
|
+
} else {
|
|
2940
|
+
const payload = Object.fromEntries(
|
|
2941
|
+
Object.entries({
|
|
2942
|
+
refresh_token: refreshToken,
|
|
2943
|
+
grant_type: "refresh_token",
|
|
2944
|
+
client_id: config.config.clientId,
|
|
2945
|
+
client_secret: config.config.clientSecret
|
|
2946
|
+
}).filter(([_, value]) => !!value)
|
|
2947
|
+
);
|
|
2948
|
+
return new Promise(function(resolve) {
|
|
2949
|
+
import_axios.default.post(
|
|
2950
|
+
`${config.baseUrl}${config.refreshTokenEndpoint ?? "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
|
|
2951
|
+
payload,
|
|
2952
|
+
{
|
|
2953
|
+
headers: {
|
|
2954
|
+
"Content-Type": config.refreshTokenEndpoint ? "application/x-www-form-urlencoded" : "multipart/form-data",
|
|
2955
|
+
Authorization: `Bearer ${accessTokenExp}`
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
).then(async (res) => {
|
|
2959
|
+
const data = res.data;
|
|
2960
|
+
await localStorage2.setToken(data.access_token);
|
|
2961
|
+
await localStorage2.setRefreshToken(data.refresh_token);
|
|
2962
|
+
import_axios.default.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
|
|
2963
|
+
originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
|
|
2964
|
+
originalRequest.data = updateTokenParamInOriginalRequest(
|
|
2965
|
+
originalRequest,
|
|
2966
|
+
data.access_token
|
|
2967
|
+
);
|
|
2968
|
+
processQueue(null, data.access_token);
|
|
2969
|
+
resolve(instance.request(originalRequest));
|
|
2970
|
+
}).catch(async (err) => {
|
|
2971
|
+
if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_BAD_REQUEST") || err?.error_code === "ERR_2FA_006") {
|
|
2972
|
+
await clearAuthToken();
|
|
2973
|
+
}
|
|
2974
|
+
if (err && err.response) {
|
|
2975
|
+
const { error_code } = err.response?.data || {};
|
|
2976
|
+
if (error_code === "AUTHEN_FAIL") {
|
|
2977
|
+
await clearAuthToken();
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
processQueue(err, null);
|
|
2981
|
+
}).finally(() => {
|
|
2982
|
+
isRefreshing = false;
|
|
2983
|
+
});
|
|
2984
|
+
});
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
return Promise.reject(await handleError3(error));
|
|
2988
|
+
}
|
|
2989
|
+
);
|
|
2990
|
+
const handleResponse = (res) => {
|
|
2991
|
+
if (res && res.data) {
|
|
2992
|
+
return res.data;
|
|
2993
|
+
}
|
|
2994
|
+
return res;
|
|
2995
|
+
};
|
|
2996
|
+
const handleError2 = (error) => {
|
|
2997
|
+
if (error.isAxiosError && error.code === "ECONNABORTED") {
|
|
2998
|
+
console.error("Request Timeout Error:", error);
|
|
2999
|
+
return "Request Timeout Error";
|
|
3000
|
+
} else if (error.isAxiosError && !error.response) {
|
|
3001
|
+
console.error("Network Error:", error);
|
|
3002
|
+
return "Network Error";
|
|
3003
|
+
} else {
|
|
3004
|
+
console.error("Other Error:", error?.response);
|
|
3005
|
+
const errorMessage = error?.response?.data?.message || "An error occurred";
|
|
3006
|
+
return { message: errorMessage, status: error?.response?.status };
|
|
3007
|
+
}
|
|
3008
|
+
};
|
|
3009
|
+
const clearAuthToken = async () => {
|
|
3010
|
+
await localStorage2.clearToken();
|
|
3011
|
+
if (typeof window !== "undefined") {
|
|
3012
|
+
window.location.href = `/login`;
|
|
3013
|
+
}
|
|
3014
|
+
};
|
|
3015
|
+
function formatUrl(url, db2) {
|
|
3016
|
+
return url + (db2 ? "?db=" + db2 : "");
|
|
3017
|
+
}
|
|
3018
|
+
const responseBody = (response) => response;
|
|
3019
|
+
const requests = {
|
|
3020
|
+
get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
|
|
3021
|
+
post: (url, body, headers) => instance.post(formatUrl(url, db), body, headers).then(responseBody),
|
|
3022
|
+
post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
|
|
3023
|
+
responseType: "arraybuffer",
|
|
3024
|
+
headers: {
|
|
3025
|
+
"Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
|
|
3026
|
+
Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
3027
|
+
}
|
|
3028
|
+
}).then(responseBody),
|
|
3029
|
+
put: (url, body, headers) => instance.put(formatUrl(url, db), body, headers).then(responseBody),
|
|
3030
|
+
patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
|
|
3031
|
+
delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
|
|
3032
|
+
};
|
|
3033
|
+
return requests;
|
|
3034
|
+
}
|
|
3035
|
+
};
|
|
2810
3036
|
|
|
2811
3037
|
// src/environment/EnvStore.ts
|
|
2812
|
-
var
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
3038
|
+
var EnvStore = class _EnvStore {
|
|
3039
|
+
static instance = null;
|
|
3040
|
+
static localStorageUtils;
|
|
3041
|
+
static sessionStorageUtils;
|
|
3042
|
+
constructor() {
|
|
3043
|
+
}
|
|
3044
|
+
static getInstance(localStorageUtils2, sessionStorageUtils2) {
|
|
3045
|
+
if (!_EnvStore.instance) {
|
|
3046
|
+
console.log("Creating new EnvStore instance");
|
|
3047
|
+
_EnvStore.instance = new _EnvStore();
|
|
3048
|
+
_EnvStore.localStorageUtils = localStorageUtils2;
|
|
3049
|
+
_EnvStore.sessionStorageUtils = sessionStorageUtils2;
|
|
3050
|
+
} else {
|
|
3051
|
+
console.log("Returning existing EnvStore instance");
|
|
3052
|
+
}
|
|
3053
|
+
return _EnvStore.instance;
|
|
3054
|
+
}
|
|
3055
|
+
static getState() {
|
|
3056
|
+
const state = envStore.getState().env;
|
|
3057
|
+
console.log("Redux env state:", state);
|
|
3058
|
+
return {
|
|
3059
|
+
baseUrl: state?.baseUrl,
|
|
3060
|
+
requests: state?.requests,
|
|
3061
|
+
context: state?.context,
|
|
3062
|
+
defaultCompany: state?.defaultCompany,
|
|
3063
|
+
config: state?.config,
|
|
3064
|
+
companies: state?.companies || [],
|
|
3065
|
+
user: state?.user,
|
|
3066
|
+
db: state?.db,
|
|
3067
|
+
refreshTokenEndpoint: state?.refreshTokenEndpoint,
|
|
3068
|
+
uid: state?.uid,
|
|
3069
|
+
lang: state?.lang,
|
|
3070
|
+
allowCompanies: state?.allowCompanies
|
|
3071
|
+
};
|
|
3072
|
+
}
|
|
3073
|
+
static setupEnv(envConfig) {
|
|
3074
|
+
const dispatch = envStore.dispatch;
|
|
3075
|
+
const env = {
|
|
3076
|
+
..._EnvStore.getState(),
|
|
3077
|
+
...envConfig,
|
|
3078
|
+
localStorageUtils: _EnvStore.localStorageUtils,
|
|
3079
|
+
sessionStorageUtils: _EnvStore.sessionStorageUtils
|
|
3080
|
+
};
|
|
3081
|
+
console.log("Setting up env with config:", envConfig);
|
|
3082
|
+
const requests = axiosClient.init(env);
|
|
3083
|
+
console.log("axiosClient.init result:", requests);
|
|
3084
|
+
dispatch(setEnv({ ...env, requests }));
|
|
3085
|
+
}
|
|
3086
|
+
static setUid(uid) {
|
|
3087
|
+
const dispatch = envStore.dispatch;
|
|
3088
|
+
dispatch(setUid(uid));
|
|
3089
|
+
}
|
|
3090
|
+
static setLang(lang) {
|
|
3091
|
+
const dispatch = envStore.dispatch;
|
|
3092
|
+
dispatch(setLang(lang));
|
|
3093
|
+
}
|
|
3094
|
+
static setAllowCompanies(allowCompanies) {
|
|
3095
|
+
const dispatch = envStore.dispatch;
|
|
3096
|
+
dispatch(setAllowCompanies(allowCompanies));
|
|
3097
|
+
}
|
|
3098
|
+
static setCompanies(companies) {
|
|
3099
|
+
const dispatch = envStore.dispatch;
|
|
3100
|
+
dispatch(setCompanies(companies));
|
|
3101
|
+
}
|
|
3102
|
+
static setDefaultCompany(company) {
|
|
3103
|
+
const dispatch = envStore.dispatch;
|
|
3104
|
+
dispatch(setDefaultCompany(company));
|
|
3105
|
+
}
|
|
3106
|
+
static setUserInfo(userInfo) {
|
|
3107
|
+
const dispatch = envStore.dispatch;
|
|
3108
|
+
dispatch(setUser(userInfo));
|
|
3109
|
+
}
|
|
2819
3110
|
};
|
|
2820
3111
|
function getEnv() {
|
|
2821
|
-
|
|
2822
|
-
return { ...env, requests };
|
|
3112
|
+
return EnvStore.getState();
|
|
2823
3113
|
}
|
|
2824
3114
|
|
|
2825
3115
|
// src/services/view-service/index.ts
|
|
@@ -3083,7 +3373,8 @@ var ViewService = {
|
|
|
3083
3373
|
},
|
|
3084
3374
|
async getVersion() {
|
|
3085
3375
|
const env = getEnv();
|
|
3086
|
-
|
|
3376
|
+
console.log("env?.requests", env, env?.requests);
|
|
3377
|
+
return env?.requests?.get("", {
|
|
3087
3378
|
headers: {
|
|
3088
3379
|
"Content-Type": "application/json"
|
|
3089
3380
|
}
|
|
@@ -3280,6 +3571,7 @@ var VersionGate = ({ children }) => {
|
|
|
3280
3571
|
};
|
|
3281
3572
|
const validateVersion = async () => {
|
|
3282
3573
|
const serverVersion = await view_service_default.getVersion();
|
|
3574
|
+
console.log("serverVersion", serverVersion);
|
|
3283
3575
|
const cached = localStorage.getItem("__api_version__");
|
|
3284
3576
|
if (cached !== serverVersion?.api_version) {
|
|
3285
3577
|
clearVersion();
|