@fctc/interface-logic 1.0.4 → 1.0.6
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/config.js +35 -5
- package/dist/config.mjs +35 -5
- package/dist/constants.d.mts +4 -1
- package/dist/constants.d.ts +4 -1
- package/dist/constants.js +3 -0
- package/dist/constants.mjs +3 -0
- package/dist/environment.d.mts +1 -0
- package/dist/environment.d.ts +1 -0
- package/dist/environment.js +37 -5
- package/dist/environment.mjs +37 -5
- package/dist/hook.d.mts +7 -1
- package/dist/hook.d.ts +7 -1
- package/dist/hook.js +325 -103
- package/dist/hook.mjs +283 -63
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +410 -3300
- package/dist/index.mjs +295 -3211
- package/dist/model.js +40 -5
- package/dist/model.mjs +40 -5
- package/dist/provider.d.mts +4 -3
- package/dist/provider.d.ts +4 -3
- package/dist/provider.js +175 -3144
- package/dist/provider.mjs +161 -3153
- package/dist/services.d.mts +32 -0
- package/dist/services.d.ts +32 -0
- package/dist/services.js +183 -5
- package/dist/services.mjs +183 -5
- package/dist/utils.d.mts +4 -1
- package/dist/utils.d.ts +4 -1
- package/dist/utils.js +21 -0
- package/dist/utils.mjs +20 -0
- package/package.json +87 -87
package/dist/model.js
CHANGED
@@ -60,6 +60,9 @@ var UriConstants = /* @__PURE__ */ ((UriConstants2) => {
|
|
60
60
|
UriConstants2["CREATE_UPDATE_PATH"] = `/create_update`;
|
61
61
|
UriConstants2["TWOFA_METHOD_PATH"] = `/id/api/v2/call`;
|
62
62
|
UriConstants2["SIGNIN_SSO"] = `/signin-sso/oauth`;
|
63
|
+
UriConstants2["GRANT_ACCESS"] = "/grant-access";
|
64
|
+
UriConstants2["TOKEN_BY_CODE"] = "/token";
|
65
|
+
UriConstants2["LOGOUT"] = "/logout";
|
63
66
|
return UriConstants2;
|
64
67
|
})(UriConstants || {});
|
65
68
|
|
@@ -2294,6 +2297,27 @@ function matchDomain(record, domain) {
|
|
2294
2297
|
return matchCondition(record, condStack.pop());
|
2295
2298
|
}
|
2296
2299
|
|
2300
|
+
// src/utils/function.ts
|
2301
|
+
var updateTokenParamInOriginalRequest = (originalRequest, newAccessToken) => {
|
2302
|
+
if (!originalRequest.data) return originalRequest.data;
|
2303
|
+
if (typeof originalRequest.data === "string") {
|
2304
|
+
try {
|
2305
|
+
const parsedData = JSON.parse(originalRequest.data);
|
2306
|
+
if (parsedData.with_context && typeof parsedData.with_context === "object") {
|
2307
|
+
parsedData.with_context.token = newAccessToken;
|
2308
|
+
}
|
2309
|
+
return JSON.stringify(parsedData);
|
2310
|
+
} catch (e) {
|
2311
|
+
console.warn("Failed to parse originalRequest.data", e);
|
2312
|
+
return originalRequest.data;
|
2313
|
+
}
|
2314
|
+
}
|
2315
|
+
if (typeof originalRequest.data === "object" && originalRequest.data.with_context) {
|
2316
|
+
originalRequest.data.with_context.token = newAccessToken;
|
2317
|
+
}
|
2318
|
+
return originalRequest.data;
|
2319
|
+
};
|
2320
|
+
|
2297
2321
|
// src/utils/storage/local-storage.ts
|
2298
2322
|
var localStorageUtils = () => {
|
2299
2323
|
const setToken = async (access_token) => {
|
@@ -2357,7 +2381,8 @@ var axiosClient = {
|
|
2357
2381
|
});
|
2358
2382
|
instance.interceptors.request.use(
|
2359
2383
|
async (config2) => {
|
2360
|
-
const
|
2384
|
+
const useRefreshToken = config2.useRefreshToken;
|
2385
|
+
const token = useRefreshToken ? await localStorage2.getRefreshToken() : await localStorage2.getAccessToken();
|
2361
2386
|
if (token) {
|
2362
2387
|
config2.headers["Authorization"] = "Bearer " + token;
|
2363
2388
|
}
|
@@ -2383,7 +2408,7 @@ var axiosClient = {
|
|
2383
2408
|
return data;
|
2384
2409
|
};
|
2385
2410
|
const originalRequest = error.config;
|
2386
|
-
if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401].includes(
|
2411
|
+
if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401, "ERR_2FA_006"].includes(
|
2387
2412
|
error.response.data.code
|
2388
2413
|
)) {
|
2389
2414
|
if (isRefreshing) {
|
@@ -2391,6 +2416,10 @@ var axiosClient = {
|
|
2391
2416
|
failedQueue.push({ resolve, reject });
|
2392
2417
|
}).then((token) => {
|
2393
2418
|
originalRequest.headers["Authorization"] = "Bearer " + token;
|
2419
|
+
originalRequest.data = updateTokenParamInOriginalRequest(
|
2420
|
+
originalRequest,
|
2421
|
+
token
|
2422
|
+
);
|
2394
2423
|
return instance.request(originalRequest);
|
2395
2424
|
}).catch(async (err) => {
|
2396
2425
|
if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
|
@@ -2415,11 +2444,11 @@ var axiosClient = {
|
|
2415
2444
|
);
|
2416
2445
|
return new Promise(function(resolve) {
|
2417
2446
|
import_axios.default.post(
|
2418
|
-
`${config.baseUrl}${"/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
|
2447
|
+
`${config.baseUrl}${config.refreshTokenEndpoint ?? "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
|
2419
2448
|
payload,
|
2420
2449
|
{
|
2421
2450
|
headers: {
|
2422
|
-
"Content-Type": "multipart/form-data",
|
2451
|
+
"Content-Type": config.refreshTokenEndpoint ? "application/x-www-form-urlencoded" : "multipart/form-data",
|
2423
2452
|
Authorization: `Bearer ${accessTokenExp}`
|
2424
2453
|
}
|
2425
2454
|
}
|
@@ -2429,10 +2458,14 @@ var axiosClient = {
|
|
2429
2458
|
await localStorage2.setRefreshToken(data.refresh_token);
|
2430
2459
|
import_axios.default.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
|
2431
2460
|
originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
|
2461
|
+
originalRequest.data = updateTokenParamInOriginalRequest(
|
2462
|
+
originalRequest,
|
2463
|
+
data.access_token
|
2464
|
+
);
|
2432
2465
|
processQueue(null, data.access_token);
|
2433
2466
|
resolve(instance.request(originalRequest));
|
2434
2467
|
}).catch(async (err) => {
|
2435
|
-
if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_BAD_REQUEST")) {
|
2468
|
+
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") {
|
2436
2469
|
await clearAuthToken();
|
2437
2470
|
}
|
2438
2471
|
if (err && err.response) {
|
@@ -3125,6 +3158,7 @@ var EnvStore = class {
|
|
3125
3158
|
db;
|
3126
3159
|
localStorageUtils;
|
3127
3160
|
sessionStorageUtils;
|
3161
|
+
refreshTokenEndpoint;
|
3128
3162
|
constructor(envStore2, localStorageUtils2, sessionStorageUtils2) {
|
3129
3163
|
this.envStore = envStore2;
|
3130
3164
|
this.localStorageUtils = localStorageUtils2;
|
@@ -3141,6 +3175,7 @@ var EnvStore = class {
|
|
3141
3175
|
this.companies = env2?.companies || [];
|
3142
3176
|
this.user = env2?.user;
|
3143
3177
|
this.db = env2?.db;
|
3178
|
+
this.refreshTokenEndpoint = env2?.refreshTokenEndpoint;
|
3144
3179
|
}
|
3145
3180
|
setupEnv(envConfig) {
|
3146
3181
|
const dispatch = this.envStore.dispatch;
|
package/dist/model.mjs
CHANGED
@@ -22,6 +22,9 @@ var UriConstants = /* @__PURE__ */ ((UriConstants2) => {
|
|
22
22
|
UriConstants2["CREATE_UPDATE_PATH"] = `/create_update`;
|
23
23
|
UriConstants2["TWOFA_METHOD_PATH"] = `/id/api/v2/call`;
|
24
24
|
UriConstants2["SIGNIN_SSO"] = `/signin-sso/oauth`;
|
25
|
+
UriConstants2["GRANT_ACCESS"] = "/grant-access";
|
26
|
+
UriConstants2["TOKEN_BY_CODE"] = "/token";
|
27
|
+
UriConstants2["LOGOUT"] = "/logout";
|
25
28
|
return UriConstants2;
|
26
29
|
})(UriConstants || {});
|
27
30
|
|
@@ -2256,6 +2259,27 @@ function matchDomain(record, domain) {
|
|
2256
2259
|
return matchCondition(record, condStack.pop());
|
2257
2260
|
}
|
2258
2261
|
|
2262
|
+
// src/utils/function.ts
|
2263
|
+
var updateTokenParamInOriginalRequest = (originalRequest, newAccessToken) => {
|
2264
|
+
if (!originalRequest.data) return originalRequest.data;
|
2265
|
+
if (typeof originalRequest.data === "string") {
|
2266
|
+
try {
|
2267
|
+
const parsedData = JSON.parse(originalRequest.data);
|
2268
|
+
if (parsedData.with_context && typeof parsedData.with_context === "object") {
|
2269
|
+
parsedData.with_context.token = newAccessToken;
|
2270
|
+
}
|
2271
|
+
return JSON.stringify(parsedData);
|
2272
|
+
} catch (e) {
|
2273
|
+
console.warn("Failed to parse originalRequest.data", e);
|
2274
|
+
return originalRequest.data;
|
2275
|
+
}
|
2276
|
+
}
|
2277
|
+
if (typeof originalRequest.data === "object" && originalRequest.data.with_context) {
|
2278
|
+
originalRequest.data.with_context.token = newAccessToken;
|
2279
|
+
}
|
2280
|
+
return originalRequest.data;
|
2281
|
+
};
|
2282
|
+
|
2259
2283
|
// src/utils/storage/local-storage.ts
|
2260
2284
|
var localStorageUtils = () => {
|
2261
2285
|
const setToken = async (access_token) => {
|
@@ -2319,7 +2343,8 @@ var axiosClient = {
|
|
2319
2343
|
});
|
2320
2344
|
instance.interceptors.request.use(
|
2321
2345
|
async (config2) => {
|
2322
|
-
const
|
2346
|
+
const useRefreshToken = config2.useRefreshToken;
|
2347
|
+
const token = useRefreshToken ? await localStorage2.getRefreshToken() : await localStorage2.getAccessToken();
|
2323
2348
|
if (token) {
|
2324
2349
|
config2.headers["Authorization"] = "Bearer " + token;
|
2325
2350
|
}
|
@@ -2345,7 +2370,7 @@ var axiosClient = {
|
|
2345
2370
|
return data;
|
2346
2371
|
};
|
2347
2372
|
const originalRequest = error.config;
|
2348
|
-
if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401].includes(
|
2373
|
+
if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401, "ERR_2FA_006"].includes(
|
2349
2374
|
error.response.data.code
|
2350
2375
|
)) {
|
2351
2376
|
if (isRefreshing) {
|
@@ -2353,6 +2378,10 @@ var axiosClient = {
|
|
2353
2378
|
failedQueue.push({ resolve, reject });
|
2354
2379
|
}).then((token) => {
|
2355
2380
|
originalRequest.headers["Authorization"] = "Bearer " + token;
|
2381
|
+
originalRequest.data = updateTokenParamInOriginalRequest(
|
2382
|
+
originalRequest,
|
2383
|
+
token
|
2384
|
+
);
|
2356
2385
|
return instance.request(originalRequest);
|
2357
2386
|
}).catch(async (err) => {
|
2358
2387
|
if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
|
@@ -2377,11 +2406,11 @@ var axiosClient = {
|
|
2377
2406
|
);
|
2378
2407
|
return new Promise(function(resolve) {
|
2379
2408
|
axios.post(
|
2380
|
-
`${config.baseUrl}${"/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
|
2409
|
+
`${config.baseUrl}${config.refreshTokenEndpoint ?? "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
|
2381
2410
|
payload,
|
2382
2411
|
{
|
2383
2412
|
headers: {
|
2384
|
-
"Content-Type": "multipart/form-data",
|
2413
|
+
"Content-Type": config.refreshTokenEndpoint ? "application/x-www-form-urlencoded" : "multipart/form-data",
|
2385
2414
|
Authorization: `Bearer ${accessTokenExp}`
|
2386
2415
|
}
|
2387
2416
|
}
|
@@ -2391,10 +2420,14 @@ var axiosClient = {
|
|
2391
2420
|
await localStorage2.setRefreshToken(data.refresh_token);
|
2392
2421
|
axios.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
|
2393
2422
|
originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
|
2423
|
+
originalRequest.data = updateTokenParamInOriginalRequest(
|
2424
|
+
originalRequest,
|
2425
|
+
data.access_token
|
2426
|
+
);
|
2394
2427
|
processQueue(null, data.access_token);
|
2395
2428
|
resolve(instance.request(originalRequest));
|
2396
2429
|
}).catch(async (err) => {
|
2397
|
-
if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_BAD_REQUEST")) {
|
2430
|
+
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") {
|
2398
2431
|
await clearAuthToken();
|
2399
2432
|
}
|
2400
2433
|
if (err && err.response) {
|
@@ -3087,6 +3120,7 @@ var EnvStore = class {
|
|
3087
3120
|
db;
|
3088
3121
|
localStorageUtils;
|
3089
3122
|
sessionStorageUtils;
|
3123
|
+
refreshTokenEndpoint;
|
3090
3124
|
constructor(envStore2, localStorageUtils2, sessionStorageUtils2) {
|
3091
3125
|
this.envStore = envStore2;
|
3092
3126
|
this.localStorageUtils = localStorageUtils2;
|
@@ -3103,6 +3137,7 @@ var EnvStore = class {
|
|
3103
3137
|
this.companies = env2?.companies || [];
|
3104
3138
|
this.user = env2?.user;
|
3105
3139
|
this.db = env2?.db;
|
3140
|
+
this.refreshTokenEndpoint = env2?.refreshTokenEndpoint;
|
3106
3141
|
}
|
3107
3142
|
setupEnv(envConfig) {
|
3108
3143
|
const dispatch = this.envStore.dispatch;
|
package/dist/provider.d.mts
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
1
2
|
import { ReactNode } from 'react';
|
2
3
|
|
3
4
|
declare const MainProvider: ({ children }: {
|
4
5
|
children: ReactNode;
|
5
|
-
}) => JSX.Element;
|
6
|
+
}) => react_jsx_runtime.JSX.Element;
|
6
7
|
|
7
8
|
declare const ReactQueryProvider: ({ children }: {
|
8
9
|
children: ReactNode;
|
9
|
-
}) => JSX.Element;
|
10
|
+
}) => react_jsx_runtime.JSX.Element;
|
10
11
|
|
11
12
|
declare const VersionGate: ({ children }: {
|
12
13
|
children: ReactNode;
|
13
|
-
}) => JSX.Element | null;
|
14
|
+
}) => react_jsx_runtime.JSX.Element | null;
|
14
15
|
|
15
16
|
export { MainProvider, ReactQueryProvider, VersionGate };
|
package/dist/provider.d.ts
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
1
2
|
import { ReactNode } from 'react';
|
2
3
|
|
3
4
|
declare const MainProvider: ({ children }: {
|
4
5
|
children: ReactNode;
|
5
|
-
}) => JSX.Element;
|
6
|
+
}) => react_jsx_runtime.JSX.Element;
|
6
7
|
|
7
8
|
declare const ReactQueryProvider: ({ children }: {
|
8
9
|
children: ReactNode;
|
9
|
-
}) => JSX.Element;
|
10
|
+
}) => react_jsx_runtime.JSX.Element;
|
10
11
|
|
11
12
|
declare const VersionGate: ({ children }: {
|
12
13
|
children: ReactNode;
|
13
|
-
}) => JSX.Element | null;
|
14
|
+
}) => react_jsx_runtime.JSX.Element | null;
|
14
15
|
|
15
16
|
export { MainProvider, ReactQueryProvider, VersionGate };
|