@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.mjs
CHANGED
|
@@ -43,16 +43,10 @@ var breadcrums_slice_default = breadcrumbsSlice.reducer;
|
|
|
43
43
|
import { createSlice as createSlice2 } from "@reduxjs/toolkit";
|
|
44
44
|
var initialState2 = {
|
|
45
45
|
baseUrl: "",
|
|
46
|
+
requests: null,
|
|
46
47
|
companies: [],
|
|
47
48
|
user: {},
|
|
48
|
-
|
|
49
|
-
refreshTokenEndpoint: "",
|
|
50
|
-
config: {
|
|
51
|
-
grantType: "",
|
|
52
|
-
clientId: "",
|
|
53
|
-
clientSecret: "",
|
|
54
|
-
redirectUri: ""
|
|
55
|
-
},
|
|
49
|
+
config: null,
|
|
56
50
|
envFile: null,
|
|
57
51
|
defaultCompany: {
|
|
58
52
|
id: null,
|
|
@@ -2769,19 +2763,315 @@ function matchDomain(record, domain) {
|
|
|
2769
2763
|
|
|
2770
2764
|
// src/utils/function.ts
|
|
2771
2765
|
import { useEffect, useState } from "react";
|
|
2766
|
+
var updateTokenParamInOriginalRequest = (originalRequest, newAccessToken) => {
|
|
2767
|
+
if (!originalRequest.data) return originalRequest.data;
|
|
2768
|
+
if (typeof originalRequest.data === "string") {
|
|
2769
|
+
try {
|
|
2770
|
+
const parsedData = JSON.parse(originalRequest.data);
|
|
2771
|
+
if (parsedData.with_context && typeof parsedData.with_context === "object") {
|
|
2772
|
+
parsedData.with_context.token = newAccessToken;
|
|
2773
|
+
}
|
|
2774
|
+
return JSON.stringify(parsedData);
|
|
2775
|
+
} catch (e) {
|
|
2776
|
+
console.warn("Failed to parse originalRequest.data", e);
|
|
2777
|
+
return originalRequest.data;
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
if (typeof originalRequest.data === "object" && originalRequest.data.with_context) {
|
|
2781
|
+
originalRequest.data.with_context.token = newAccessToken;
|
|
2782
|
+
}
|
|
2783
|
+
return originalRequest.data;
|
|
2784
|
+
};
|
|
2785
|
+
|
|
2786
|
+
// src/utils/storage/local-storage.ts
|
|
2787
|
+
var localStorageUtils = () => {
|
|
2788
|
+
const setToken = async (access_token) => {
|
|
2789
|
+
localStorage.setItem("accessToken", access_token);
|
|
2790
|
+
};
|
|
2791
|
+
const setRefreshToken = async (refresh_token) => {
|
|
2792
|
+
localStorage.setItem("refreshToken", refresh_token);
|
|
2793
|
+
};
|
|
2794
|
+
const getAccessToken = async () => {
|
|
2795
|
+
return localStorage.getItem("accessToken");
|
|
2796
|
+
};
|
|
2797
|
+
const getRefreshToken = async () => {
|
|
2798
|
+
return localStorage.getItem("refreshToken");
|
|
2799
|
+
};
|
|
2800
|
+
const clearToken = async () => {
|
|
2801
|
+
localStorage.removeItem("accessToken");
|
|
2802
|
+
localStorage.removeItem("refreshToken");
|
|
2803
|
+
};
|
|
2804
|
+
return {
|
|
2805
|
+
setToken,
|
|
2806
|
+
setRefreshToken,
|
|
2807
|
+
getAccessToken,
|
|
2808
|
+
getRefreshToken,
|
|
2809
|
+
clearToken
|
|
2810
|
+
};
|
|
2811
|
+
};
|
|
2812
|
+
|
|
2813
|
+
// src/utils/storage/session-storage.ts
|
|
2814
|
+
var sessionStorageUtils = () => {
|
|
2815
|
+
const getBrowserSession = async () => {
|
|
2816
|
+
return sessionStorage.getItem("browserSession");
|
|
2817
|
+
};
|
|
2818
|
+
return {
|
|
2819
|
+
getBrowserSession
|
|
2820
|
+
};
|
|
2821
|
+
};
|
|
2822
|
+
|
|
2823
|
+
// src/configs/axios-client.ts
|
|
2824
|
+
var axiosClient = {
|
|
2825
|
+
init(config) {
|
|
2826
|
+
const localStorage2 = config?.localStorageUtils ?? localStorageUtils();
|
|
2827
|
+
const sessionStorage2 = config?.sessionStorageUtils ?? sessionStorageUtils();
|
|
2828
|
+
const db = config?.db;
|
|
2829
|
+
let isRefreshing = false;
|
|
2830
|
+
let failedQueue = [];
|
|
2831
|
+
const processQueue = (error, token = null) => {
|
|
2832
|
+
failedQueue?.forEach((prom) => {
|
|
2833
|
+
if (error) {
|
|
2834
|
+
prom.reject(error);
|
|
2835
|
+
} else {
|
|
2836
|
+
prom.resolve(token);
|
|
2837
|
+
}
|
|
2838
|
+
});
|
|
2839
|
+
failedQueue = [];
|
|
2840
|
+
};
|
|
2841
|
+
const instance = axios.create({
|
|
2842
|
+
adapter: axios.defaults.adapter,
|
|
2843
|
+
baseURL: config.baseUrl,
|
|
2844
|
+
timeout: 5e4,
|
|
2845
|
+
paramsSerializer: (params) => new URLSearchParams(params).toString()
|
|
2846
|
+
});
|
|
2847
|
+
instance.interceptors.request.use(
|
|
2848
|
+
async (config2) => {
|
|
2849
|
+
const useRefreshToken = config2.useRefreshToken;
|
|
2850
|
+
const token = useRefreshToken ? await localStorage2.getRefreshToken() : await localStorage2.getAccessToken();
|
|
2851
|
+
if (token) {
|
|
2852
|
+
config2.headers["Authorization"] = "Bearer " + token;
|
|
2853
|
+
}
|
|
2854
|
+
return config2;
|
|
2855
|
+
},
|
|
2856
|
+
(error) => {
|
|
2857
|
+
Promise.reject(error);
|
|
2858
|
+
}
|
|
2859
|
+
);
|
|
2860
|
+
instance.interceptors.response.use(
|
|
2861
|
+
(response) => {
|
|
2862
|
+
return handleResponse(response);
|
|
2863
|
+
},
|
|
2864
|
+
async (error) => {
|
|
2865
|
+
const handleError3 = async (error2) => {
|
|
2866
|
+
if (!error2.response) {
|
|
2867
|
+
return error2;
|
|
2868
|
+
}
|
|
2869
|
+
const { data } = error2.response;
|
|
2870
|
+
if (data && data.code === 400 && ["invalid_grant"].includes(data.data?.error)) {
|
|
2871
|
+
await clearAuthToken();
|
|
2872
|
+
}
|
|
2873
|
+
return data;
|
|
2874
|
+
};
|
|
2875
|
+
const originalRequest = error.config;
|
|
2876
|
+
if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401, "ERR_2FA_006"].includes(
|
|
2877
|
+
error.response.data.code
|
|
2878
|
+
)) {
|
|
2879
|
+
if (isRefreshing) {
|
|
2880
|
+
return new Promise(function(resolve, reject) {
|
|
2881
|
+
failedQueue.push({ resolve, reject });
|
|
2882
|
+
}).then((token) => {
|
|
2883
|
+
originalRequest.headers["Authorization"] = "Bearer " + token;
|
|
2884
|
+
originalRequest.data = updateTokenParamInOriginalRequest(
|
|
2885
|
+
originalRequest,
|
|
2886
|
+
token
|
|
2887
|
+
);
|
|
2888
|
+
return instance.request(originalRequest);
|
|
2889
|
+
}).catch(async (err) => {
|
|
2890
|
+
if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
|
|
2891
|
+
await clearAuthToken();
|
|
2892
|
+
}
|
|
2893
|
+
});
|
|
2894
|
+
}
|
|
2895
|
+
const browserSession = await sessionStorage2.getBrowserSession();
|
|
2896
|
+
const refreshToken = await localStorage2.getRefreshToken();
|
|
2897
|
+
const accessTokenExp = await localStorage2.getAccessToken();
|
|
2898
|
+
isRefreshing = true;
|
|
2899
|
+
if (!refreshToken && (!browserSession || browserSession == "unActive")) {
|
|
2900
|
+
await clearAuthToken();
|
|
2901
|
+
} else {
|
|
2902
|
+
const payload = Object.fromEntries(
|
|
2903
|
+
Object.entries({
|
|
2904
|
+
refresh_token: refreshToken,
|
|
2905
|
+
grant_type: "refresh_token",
|
|
2906
|
+
client_id: config.config.clientId,
|
|
2907
|
+
client_secret: config.config.clientSecret
|
|
2908
|
+
}).filter(([_, value]) => !!value)
|
|
2909
|
+
);
|
|
2910
|
+
return new Promise(function(resolve) {
|
|
2911
|
+
axios.post(
|
|
2912
|
+
`${config.baseUrl}${config.refreshTokenEndpoint ?? "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
|
|
2913
|
+
payload,
|
|
2914
|
+
{
|
|
2915
|
+
headers: {
|
|
2916
|
+
"Content-Type": config.refreshTokenEndpoint ? "application/x-www-form-urlencoded" : "multipart/form-data",
|
|
2917
|
+
Authorization: `Bearer ${accessTokenExp}`
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
).then(async (res) => {
|
|
2921
|
+
const data = res.data;
|
|
2922
|
+
await localStorage2.setToken(data.access_token);
|
|
2923
|
+
await localStorage2.setRefreshToken(data.refresh_token);
|
|
2924
|
+
axios.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
|
|
2925
|
+
originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
|
|
2926
|
+
originalRequest.data = updateTokenParamInOriginalRequest(
|
|
2927
|
+
originalRequest,
|
|
2928
|
+
data.access_token
|
|
2929
|
+
);
|
|
2930
|
+
processQueue(null, data.access_token);
|
|
2931
|
+
resolve(instance.request(originalRequest));
|
|
2932
|
+
}).catch(async (err) => {
|
|
2933
|
+
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") {
|
|
2934
|
+
await clearAuthToken();
|
|
2935
|
+
}
|
|
2936
|
+
if (err && err.response) {
|
|
2937
|
+
const { error_code } = err.response?.data || {};
|
|
2938
|
+
if (error_code === "AUTHEN_FAIL") {
|
|
2939
|
+
await clearAuthToken();
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2942
|
+
processQueue(err, null);
|
|
2943
|
+
}).finally(() => {
|
|
2944
|
+
isRefreshing = false;
|
|
2945
|
+
});
|
|
2946
|
+
});
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
return Promise.reject(await handleError3(error));
|
|
2950
|
+
}
|
|
2951
|
+
);
|
|
2952
|
+
const handleResponse = (res) => {
|
|
2953
|
+
if (res && res.data) {
|
|
2954
|
+
return res.data;
|
|
2955
|
+
}
|
|
2956
|
+
return res;
|
|
2957
|
+
};
|
|
2958
|
+
const handleError2 = (error) => {
|
|
2959
|
+
if (error.isAxiosError && error.code === "ECONNABORTED") {
|
|
2960
|
+
console.error("Request Timeout Error:", error);
|
|
2961
|
+
return "Request Timeout Error";
|
|
2962
|
+
} else if (error.isAxiosError && !error.response) {
|
|
2963
|
+
console.error("Network Error:", error);
|
|
2964
|
+
return "Network Error";
|
|
2965
|
+
} else {
|
|
2966
|
+
console.error("Other Error:", error?.response);
|
|
2967
|
+
const errorMessage = error?.response?.data?.message || "An error occurred";
|
|
2968
|
+
return { message: errorMessage, status: error?.response?.status };
|
|
2969
|
+
}
|
|
2970
|
+
};
|
|
2971
|
+
const clearAuthToken = async () => {
|
|
2972
|
+
await localStorage2.clearToken();
|
|
2973
|
+
if (typeof window !== "undefined") {
|
|
2974
|
+
window.location.href = `/login`;
|
|
2975
|
+
}
|
|
2976
|
+
};
|
|
2977
|
+
function formatUrl(url, db2) {
|
|
2978
|
+
return url + (db2 ? "?db=" + db2 : "");
|
|
2979
|
+
}
|
|
2980
|
+
const responseBody = (response) => response;
|
|
2981
|
+
const requests = {
|
|
2982
|
+
get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
|
|
2983
|
+
post: (url, body, headers) => instance.post(formatUrl(url, db), body, headers).then(responseBody),
|
|
2984
|
+
post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
|
|
2985
|
+
responseType: "arraybuffer",
|
|
2986
|
+
headers: {
|
|
2987
|
+
"Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
|
|
2988
|
+
Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
2989
|
+
}
|
|
2990
|
+
}).then(responseBody),
|
|
2991
|
+
put: (url, body, headers) => instance.put(formatUrl(url, db), body, headers).then(responseBody),
|
|
2992
|
+
patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
|
|
2993
|
+
delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
|
|
2994
|
+
};
|
|
2995
|
+
return requests;
|
|
2996
|
+
}
|
|
2997
|
+
};
|
|
2772
2998
|
|
|
2773
2999
|
// src/environment/EnvStore.ts
|
|
2774
|
-
var
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
3000
|
+
var EnvStore = class _EnvStore {
|
|
3001
|
+
static instance = null;
|
|
3002
|
+
static localStorageUtils;
|
|
3003
|
+
static sessionStorageUtils;
|
|
3004
|
+
constructor() {
|
|
3005
|
+
}
|
|
3006
|
+
static getInstance(localStorageUtils2, sessionStorageUtils2) {
|
|
3007
|
+
if (!_EnvStore.instance) {
|
|
3008
|
+
console.log("Creating new EnvStore instance");
|
|
3009
|
+
_EnvStore.instance = new _EnvStore();
|
|
3010
|
+
_EnvStore.localStorageUtils = localStorageUtils2;
|
|
3011
|
+
_EnvStore.sessionStorageUtils = sessionStorageUtils2;
|
|
3012
|
+
} else {
|
|
3013
|
+
console.log("Returning existing EnvStore instance");
|
|
3014
|
+
}
|
|
3015
|
+
return _EnvStore.instance;
|
|
3016
|
+
}
|
|
3017
|
+
static getState() {
|
|
3018
|
+
const state = envStore.getState().env;
|
|
3019
|
+
console.log("Redux env state:", state);
|
|
3020
|
+
return {
|
|
3021
|
+
baseUrl: state?.baseUrl,
|
|
3022
|
+
requests: state?.requests,
|
|
3023
|
+
context: state?.context,
|
|
3024
|
+
defaultCompany: state?.defaultCompany,
|
|
3025
|
+
config: state?.config,
|
|
3026
|
+
companies: state?.companies || [],
|
|
3027
|
+
user: state?.user,
|
|
3028
|
+
db: state?.db,
|
|
3029
|
+
refreshTokenEndpoint: state?.refreshTokenEndpoint,
|
|
3030
|
+
uid: state?.uid,
|
|
3031
|
+
lang: state?.lang,
|
|
3032
|
+
allowCompanies: state?.allowCompanies
|
|
3033
|
+
};
|
|
3034
|
+
}
|
|
3035
|
+
static setupEnv(envConfig) {
|
|
3036
|
+
const dispatch = envStore.dispatch;
|
|
3037
|
+
const env = {
|
|
3038
|
+
..._EnvStore.getState(),
|
|
3039
|
+
...envConfig,
|
|
3040
|
+
localStorageUtils: _EnvStore.localStorageUtils,
|
|
3041
|
+
sessionStorageUtils: _EnvStore.sessionStorageUtils
|
|
3042
|
+
};
|
|
3043
|
+
console.log("Setting up env with config:", envConfig);
|
|
3044
|
+
const requests = axiosClient.init(env);
|
|
3045
|
+
console.log("axiosClient.init result:", requests);
|
|
3046
|
+
dispatch(setEnv({ ...env, requests }));
|
|
3047
|
+
}
|
|
3048
|
+
static setUid(uid) {
|
|
3049
|
+
const dispatch = envStore.dispatch;
|
|
3050
|
+
dispatch(setUid(uid));
|
|
3051
|
+
}
|
|
3052
|
+
static setLang(lang) {
|
|
3053
|
+
const dispatch = envStore.dispatch;
|
|
3054
|
+
dispatch(setLang(lang));
|
|
3055
|
+
}
|
|
3056
|
+
static setAllowCompanies(allowCompanies) {
|
|
3057
|
+
const dispatch = envStore.dispatch;
|
|
3058
|
+
dispatch(setAllowCompanies(allowCompanies));
|
|
3059
|
+
}
|
|
3060
|
+
static setCompanies(companies) {
|
|
3061
|
+
const dispatch = envStore.dispatch;
|
|
3062
|
+
dispatch(setCompanies(companies));
|
|
3063
|
+
}
|
|
3064
|
+
static setDefaultCompany(company) {
|
|
3065
|
+
const dispatch = envStore.dispatch;
|
|
3066
|
+
dispatch(setDefaultCompany(company));
|
|
3067
|
+
}
|
|
3068
|
+
static setUserInfo(userInfo) {
|
|
3069
|
+
const dispatch = envStore.dispatch;
|
|
3070
|
+
dispatch(setUser(userInfo));
|
|
3071
|
+
}
|
|
2781
3072
|
};
|
|
2782
3073
|
function getEnv() {
|
|
2783
|
-
|
|
2784
|
-
return { ...env, requests };
|
|
3074
|
+
return EnvStore.getState();
|
|
2785
3075
|
}
|
|
2786
3076
|
|
|
2787
3077
|
// src/services/view-service/index.ts
|
|
@@ -3045,7 +3335,8 @@ var ViewService = {
|
|
|
3045
3335
|
},
|
|
3046
3336
|
async getVersion() {
|
|
3047
3337
|
const env = getEnv();
|
|
3048
|
-
|
|
3338
|
+
console.log("env?.requests", env, env?.requests);
|
|
3339
|
+
return env?.requests?.get("", {
|
|
3049
3340
|
headers: {
|
|
3050
3341
|
"Content-Type": "application/json"
|
|
3051
3342
|
}
|
|
@@ -3242,6 +3533,7 @@ var VersionGate = ({ children }) => {
|
|
|
3242
3533
|
};
|
|
3243
3534
|
const validateVersion = async () => {
|
|
3244
3535
|
const serverVersion = await view_service_default.getVersion();
|
|
3536
|
+
console.log("serverVersion", serverVersion);
|
|
3245
3537
|
const cached = localStorage.getItem("__api_version__");
|
|
3246
3538
|
if (cached !== serverVersion?.api_version) {
|
|
3247
3539
|
clearVersion();
|
package/dist/services.d.mts
CHANGED
|
@@ -51,7 +51,6 @@ declare const AuthService: {
|
|
|
51
51
|
}): Promise<any>;
|
|
52
52
|
updatePassword(data: UpdatePasswordRequest, token: string | null): Promise<any>;
|
|
53
53
|
isValidToken(token: string | null): Promise<any>;
|
|
54
|
-
isValidActionToken(actionToken: string | null, path: string): Promise<any>;
|
|
55
54
|
loginSocial({ db, state, access_token, }: {
|
|
56
55
|
db: string;
|
|
57
56
|
state: object;
|
package/dist/services.d.ts
CHANGED
|
@@ -51,7 +51,6 @@ declare const AuthService: {
|
|
|
51
51
|
}): Promise<any>;
|
|
52
52
|
updatePassword(data: UpdatePasswordRequest, token: string | null): Promise<any>;
|
|
53
53
|
isValidToken(token: string | null): Promise<any>;
|
|
54
|
-
isValidActionToken(actionToken: string | null, path: string): Promise<any>;
|
|
55
54
|
loginSocial({ db, state, access_token, }: {
|
|
56
55
|
db: string;
|
|
57
56
|
state: object;
|