@fctc/interface-logic 1.7.3 → 1.7.4
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 +1 -4
- package/dist/configs.d.ts +1 -4
- package/dist/configs.js +9 -12
- package/dist/configs.mjs +9 -12
- package/dist/environment.d.mts +35 -54
- package/dist/environment.d.ts +35 -54
- package/dist/environment.js +2793 -2869
- package/dist/environment.mjs +2792 -2867
- package/dist/hooks.d.mts +7 -2
- package/dist/hooks.d.ts +7 -2
- package/dist/hooks.js +2733 -3010
- package/dist/hooks.mjs +2685 -2963
- package/dist/provider.js +19 -327
- package/dist/provider.mjs +19 -327
- package/dist/services.d.mts +2 -1
- package/dist/services.d.ts +2 -1
- package/dist/services.js +2560 -2853
- package/dist/services.mjs +2560 -2853
- package/dist/store.d.mts +224 -28
- package/dist/store.d.ts +224 -28
- package/dist/store.js +20 -6
- package/dist/store.mjs +20 -6
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/{view-type-BGJfDe73.d.mts → view-type-D8ukwj_2.d.mts} +1 -1
- package/dist/{view-type-BGJfDe73.d.ts → view-type-D8ukwj_2.d.ts} +1 -1
- package/package.json +81 -81
package/dist/provider.js
CHANGED
|
@@ -81,11 +81,25 @@ var breadcrums_slice_default = breadcrumbsSlice.reducer;
|
|
|
81
81
|
var import_toolkit2 = require("@reduxjs/toolkit");
|
|
82
82
|
var initialState2 = {
|
|
83
83
|
baseUrl: "",
|
|
84
|
-
requests: null,
|
|
85
84
|
companies: [],
|
|
86
85
|
user: {},
|
|
87
|
-
|
|
86
|
+
db: "",
|
|
87
|
+
refreshTokenEndpoint: "",
|
|
88
|
+
config: {
|
|
89
|
+
grantType: "",
|
|
90
|
+
clientId: "",
|
|
91
|
+
clientSecret: "",
|
|
92
|
+
redirectUri: ""
|
|
93
|
+
},
|
|
88
94
|
envFile: null,
|
|
95
|
+
requests: {
|
|
96
|
+
get: async (url, headers) => ({}),
|
|
97
|
+
post: async (url, body, headers) => ({}),
|
|
98
|
+
post_excel: async (url, body, headers) => ({}),
|
|
99
|
+
put: async (url, body, headers) => ({}),
|
|
100
|
+
patch: async (url, body) => ({}),
|
|
101
|
+
delete: async (url, body) => ({})
|
|
102
|
+
},
|
|
89
103
|
defaultCompany: {
|
|
90
104
|
id: null,
|
|
91
105
|
logo: "",
|
|
@@ -2801,331 +2815,11 @@ function matchDomain(record, domain) {
|
|
|
2801
2815
|
|
|
2802
2816
|
// src/utils/function.ts
|
|
2803
2817
|
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
|
-
};
|
|
3036
2818
|
|
|
3037
2819
|
// src/environment/EnvStore.ts
|
|
3038
|
-
var EnvStore = class _EnvStore {
|
|
3039
|
-
static instance = null;
|
|
3040
|
-
envStore;
|
|
3041
|
-
baseUrl;
|
|
3042
|
-
requests;
|
|
3043
|
-
context;
|
|
3044
|
-
defaultCompany;
|
|
3045
|
-
config;
|
|
3046
|
-
companies;
|
|
3047
|
-
user;
|
|
3048
|
-
db;
|
|
3049
|
-
localStorageUtils;
|
|
3050
|
-
sessionStorageUtils;
|
|
3051
|
-
refreshTokenEndpoint;
|
|
3052
|
-
constructor(envStore2, localStorageUtils2, sessionStorageUtils2) {
|
|
3053
|
-
this.envStore = envStore2;
|
|
3054
|
-
this.localStorageUtils = localStorageUtils2;
|
|
3055
|
-
this.sessionStorageUtils = sessionStorageUtils2;
|
|
3056
|
-
this.setup();
|
|
3057
|
-
}
|
|
3058
|
-
static getInstance(envStore2, localStorageUtils2, sessionStorageUtils2) {
|
|
3059
|
-
if (!_EnvStore.instance) {
|
|
3060
|
-
_EnvStore.instance = new _EnvStore(
|
|
3061
|
-
envStore2,
|
|
3062
|
-
localStorageUtils2,
|
|
3063
|
-
sessionStorageUtils2
|
|
3064
|
-
);
|
|
3065
|
-
}
|
|
3066
|
-
return _EnvStore.instance;
|
|
3067
|
-
}
|
|
3068
|
-
setup() {
|
|
3069
|
-
const env = this.envStore.getState().env;
|
|
3070
|
-
this.baseUrl = env?.baseUrl;
|
|
3071
|
-
this.requests = env?.requests;
|
|
3072
|
-
this.context = env?.context;
|
|
3073
|
-
this.defaultCompany = env?.defaultCompany;
|
|
3074
|
-
this.config = env?.config;
|
|
3075
|
-
this.companies = env?.companies || [];
|
|
3076
|
-
this.user = env?.user;
|
|
3077
|
-
this.db = env?.db;
|
|
3078
|
-
this.refreshTokenEndpoint = env?.refreshTokenEndpoint;
|
|
3079
|
-
console.log("Env setup:", this);
|
|
3080
|
-
}
|
|
3081
|
-
setupEnv(envConfig) {
|
|
3082
|
-
const dispatch = this.envStore.dispatch;
|
|
3083
|
-
const env = {
|
|
3084
|
-
...envConfig,
|
|
3085
|
-
localStorageUtils: this.localStorageUtils,
|
|
3086
|
-
sessionStorageUtils: this.sessionStorageUtils
|
|
3087
|
-
};
|
|
3088
|
-
const requests = axiosClient.init(env);
|
|
3089
|
-
dispatch(setEnv({ ...env, requests }));
|
|
3090
|
-
this.setup();
|
|
3091
|
-
}
|
|
3092
|
-
setUid(uid) {
|
|
3093
|
-
const dispatch = this.envStore.dispatch;
|
|
3094
|
-
dispatch(setUid(uid));
|
|
3095
|
-
this.setup();
|
|
3096
|
-
}
|
|
3097
|
-
setLang(lang) {
|
|
3098
|
-
const dispatch = this.envStore.dispatch;
|
|
3099
|
-
dispatch(setLang(lang));
|
|
3100
|
-
this.setup();
|
|
3101
|
-
}
|
|
3102
|
-
setAllowCompanies(allowCompanies) {
|
|
3103
|
-
const dispatch = this.envStore.dispatch;
|
|
3104
|
-
dispatch(setAllowCompanies(allowCompanies));
|
|
3105
|
-
this.setup();
|
|
3106
|
-
}
|
|
3107
|
-
setCompanies(companies) {
|
|
3108
|
-
const dispatch = this.envStore.dispatch;
|
|
3109
|
-
dispatch(setCompanies(companies));
|
|
3110
|
-
this.setup();
|
|
3111
|
-
}
|
|
3112
|
-
setDefaultCompany(company) {
|
|
3113
|
-
const dispatch = this.envStore.dispatch;
|
|
3114
|
-
dispatch(setDefaultCompany(company));
|
|
3115
|
-
this.setup();
|
|
3116
|
-
}
|
|
3117
|
-
setUserInfo(userInfo) {
|
|
3118
|
-
const dispatch = this.envStore.dispatch;
|
|
3119
|
-
dispatch(setUser(userInfo));
|
|
3120
|
-
this.setup();
|
|
3121
|
-
}
|
|
3122
|
-
};
|
|
3123
2820
|
function getEnv() {
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
throw new Error("EnvStore has not been initialized \u2014 call initEnv() first");
|
|
3127
|
-
}
|
|
3128
|
-
return instance;
|
|
2821
|
+
console.log("getEnv", envStore.getState().env);
|
|
2822
|
+
return envStore.getState().env;
|
|
3129
2823
|
}
|
|
3130
2824
|
|
|
3131
2825
|
// src/services/view-service/index.ts
|
|
@@ -3389,8 +3083,7 @@ var ViewService = {
|
|
|
3389
3083
|
},
|
|
3390
3084
|
async getVersion() {
|
|
3391
3085
|
const env = getEnv();
|
|
3392
|
-
|
|
3393
|
-
return env?.requests?.get("", {
|
|
3086
|
+
return env?.requests.get("", {
|
|
3394
3087
|
headers: {
|
|
3395
3088
|
"Content-Type": "application/json"
|
|
3396
3089
|
}
|
|
@@ -3587,7 +3280,6 @@ var VersionGate = ({ children }) => {
|
|
|
3587
3280
|
};
|
|
3588
3281
|
const validateVersion = async () => {
|
|
3589
3282
|
const serverVersion = await view_service_default.getVersion();
|
|
3590
|
-
console.log("serverVersion", serverVersion);
|
|
3591
3283
|
const cached = localStorage.getItem("__api_version__");
|
|
3592
3284
|
if (cached !== serverVersion?.api_version) {
|
|
3593
3285
|
clearVersion();
|