@fctc/interface-logic 1.2.0 → 1.2.2

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/provider.mjs CHANGED
@@ -2763,6 +2763,25 @@ function matchDomain(record, domain) {
2763
2763
 
2764
2764
  // src/utils/function.ts
2765
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
+ };
2766
2785
 
2767
2786
  // src/utils/storage/local-storage.ts
2768
2787
  var localStorageUtils = () => {
@@ -2827,7 +2846,8 @@ var axiosClient = {
2827
2846
  });
2828
2847
  instance.interceptors.request.use(
2829
2848
  async (config2) => {
2830
- const token = await localStorage2.getAccessToken();
2849
+ const useRefreshToken = config2.useRefreshToken;
2850
+ const token = useRefreshToken ? await localStorage2.getRefreshToken() : await localStorage2.getAccessToken();
2831
2851
  if (token) {
2832
2852
  config2.headers["Authorization"] = "Bearer " + token;
2833
2853
  }
@@ -2853,7 +2873,7 @@ var axiosClient = {
2853
2873
  return data;
2854
2874
  };
2855
2875
  const originalRequest = error.config;
2856
- if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401].includes(
2876
+ if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401, "ERR_2FA_006"].includes(
2857
2877
  error.response.data.code
2858
2878
  )) {
2859
2879
  if (isRefreshing) {
@@ -2861,6 +2881,10 @@ var axiosClient = {
2861
2881
  failedQueue.push({ resolve, reject });
2862
2882
  }).then((token) => {
2863
2883
  originalRequest.headers["Authorization"] = "Bearer " + token;
2884
+ originalRequest.data = updateTokenParamInOriginalRequest(
2885
+ originalRequest,
2886
+ token
2887
+ );
2864
2888
  return instance.request(originalRequest);
2865
2889
  }).catch(async (err) => {
2866
2890
  if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
@@ -2885,11 +2909,11 @@ var axiosClient = {
2885
2909
  );
2886
2910
  return new Promise(function(resolve) {
2887
2911
  axios.post(
2888
- `${config.baseUrl}${"/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
2912
+ `${config.baseUrl}${config.refreshTokenEndpoint ?? "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
2889
2913
  payload,
2890
2914
  {
2891
2915
  headers: {
2892
- "Content-Type": "multipart/form-data",
2916
+ "Content-Type": config.refreshTokenEndpoint ? "application/x-www-form-urlencoded" : "multipart/form-data",
2893
2917
  Authorization: `Bearer ${accessTokenExp}`
2894
2918
  }
2895
2919
  }
@@ -2899,10 +2923,14 @@ var axiosClient = {
2899
2923
  await localStorage2.setRefreshToken(data.refresh_token);
2900
2924
  axios.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
2901
2925
  originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
2926
+ originalRequest.data = updateTokenParamInOriginalRequest(
2927
+ originalRequest,
2928
+ data.access_token
2929
+ );
2902
2930
  processQueue(null, data.access_token);
2903
2931
  resolve(instance.request(originalRequest));
2904
2932
  }).catch(async (err) => {
2905
- if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_BAD_REQUEST")) {
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") {
2906
2934
  await clearAuthToken();
2907
2935
  }
2908
2936
  if (err && err.response) {
@@ -2952,7 +2980,7 @@ var axiosClient = {
2952
2980
  const responseBody = (response) => response;
2953
2981
  const requests = {
2954
2982
  get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
2955
- post: (url, body, headers) => instance.post(formatUrl(url, db), body, { headers }).then(responseBody),
2983
+ post: (url, body, headers) => instance.post(formatUrl(url, db), body, headers).then(responseBody),
2956
2984
  post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
2957
2985
  responseType: "arraybuffer",
2958
2986
  headers: {
@@ -2981,6 +3009,7 @@ var EnvStore = class {
2981
3009
  db;
2982
3010
  localStorageUtils;
2983
3011
  sessionStorageUtils;
3012
+ refreshTokenEndpoint;
2984
3013
  constructor(envStore2, localStorageUtils2, sessionStorageUtils2) {
2985
3014
  this.envStore = envStore2;
2986
3015
  this.localStorageUtils = localStorageUtils2;
@@ -2997,6 +3026,7 @@ var EnvStore = class {
2997
3026
  this.companies = env2?.companies || [];
2998
3027
  this.user = env2?.user;
2999
3028
  this.db = env2?.db;
3029
+ this.refreshTokenEndpoint = env2?.refreshTokenEndpoint;
3000
3030
  }
3001
3031
  setupEnv(envConfig) {
3002
3032
  const dispatch = this.envStore.dispatch;
@@ -3332,14 +3362,18 @@ var ViewService = {
3332
3362
  async verify2FA({
3333
3363
  method,
3334
3364
  with_context,
3335
- code
3365
+ code,
3366
+ device,
3367
+ location
3336
3368
  }) {
3337
3369
  const env2 = getEnv();
3338
3370
  const jsonData = {
3339
3371
  method,
3340
3372
  kwargs: {
3341
3373
  vals: {
3342
- code
3374
+ code,
3375
+ device,
3376
+ location
3343
3377
  }
3344
3378
  },
3345
3379
  with_context
@@ -3347,7 +3381,8 @@ var ViewService = {
3347
3381
  return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3348
3382
  headers: {
3349
3383
  "Content-Type": "application/json"
3350
- }
3384
+ },
3385
+ withCredentials: true
3351
3386
  });
3352
3387
  },
3353
3388
  async signInSSO({
@@ -3366,7 +3401,120 @@ var ViewService = {
3366
3401
  });
3367
3402
  const url = `${path}?${params.toString()}`;
3368
3403
  return env2?.requests.get(url, {
3369
- credentials: "include",
3404
+ headers: {
3405
+ "Content-Type": "application/json"
3406
+ },
3407
+ withCredentials: true
3408
+ });
3409
+ },
3410
+ async grantAccess({
3411
+ redirect_uri,
3412
+ state,
3413
+ client_id,
3414
+ scopes
3415
+ }) {
3416
+ const env2 = getEnv();
3417
+ const jsonData = {
3418
+ redirect_uri,
3419
+ state,
3420
+ client_id,
3421
+ scopes
3422
+ };
3423
+ return env2?.requests.post("/grant-access" /* GRANT_ACCESS */, jsonData, {
3424
+ headers: {
3425
+ "Content-Type": "application/json"
3426
+ },
3427
+ withCredentials: true
3428
+ });
3429
+ },
3430
+ async getFieldsViewSecurity({
3431
+ method,
3432
+ token,
3433
+ views
3434
+ }) {
3435
+ const env2 = getEnv();
3436
+ const jsonData = {
3437
+ method,
3438
+ kwargs: {
3439
+ views
3440
+ },
3441
+ with_context: {
3442
+ token
3443
+ }
3444
+ };
3445
+ return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3446
+ headers: {
3447
+ "Content-Type": "application/json"
3448
+ }
3449
+ });
3450
+ },
3451
+ async settingsWebRead2fa({
3452
+ method,
3453
+ model,
3454
+ kwargs,
3455
+ token
3456
+ }) {
3457
+ const env2 = getEnv();
3458
+ const jsonData = {
3459
+ method,
3460
+ model,
3461
+ kwargs,
3462
+ with_context: {
3463
+ token
3464
+ }
3465
+ };
3466
+ return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3467
+ headers: {
3468
+ "Content-Type": "application/json"
3469
+ }
3470
+ });
3471
+ },
3472
+ async requestSetupTotp({ method, token }) {
3473
+ const env2 = getEnv();
3474
+ const jsonData = {
3475
+ method,
3476
+ with_context: {
3477
+ token
3478
+ }
3479
+ };
3480
+ return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3481
+ headers: {
3482
+ "Content-Type": "application/json"
3483
+ }
3484
+ });
3485
+ },
3486
+ async verifyTotp({
3487
+ method,
3488
+ action_token,
3489
+ code
3490
+ }) {
3491
+ const env2 = getEnv();
3492
+ const jsonData = {
3493
+ method,
3494
+ kwargs: {
3495
+ vals: {
3496
+ code
3497
+ }
3498
+ },
3499
+ with_context: {
3500
+ action_token
3501
+ }
3502
+ };
3503
+ return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3504
+ headers: {
3505
+ "Content-Type": "application/json"
3506
+ }
3507
+ });
3508
+ },
3509
+ async removeTotpSetUp({ method, token }) {
3510
+ const env2 = getEnv();
3511
+ const jsonData = {
3512
+ method,
3513
+ with_context: {
3514
+ token
3515
+ }
3516
+ };
3517
+ return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3370
3518
  headers: {
3371
3519
  "Content-Type": "application/json"
3372
3520
  }
@@ -60,6 +60,8 @@ declare const AuthService: {
60
60
  access_token: string;
61
61
  }): Promise<any>;
62
62
  getProviders(db?: string): Promise<any>;
63
+ getAccessByCode(code: string): Promise<any>;
64
+ logout(data: string): Promise<any>;
63
65
  };
64
66
 
65
67
  declare const CompanyService: {
@@ -180,7 +182,7 @@ declare const ModelService: {
180
182
  };
181
183
 
182
184
  declare const UserService: {
183
- getProfile(): Promise<any>;
185
+ getProfile(path?: string): Promise<any>;
184
186
  getUser({ context, id }: {
185
187
  context: any;
186
188
  id: any;
@@ -207,10 +209,12 @@ declare const ViewService: {
207
209
  method: string;
208
210
  with_context: any;
209
211
  }): Promise<any>;
210
- verify2FA({ method, with_context, code, }: {
212
+ verify2FA({ method, with_context, code, device, location, }: {
211
213
  method: string;
212
214
  with_context: any;
213
215
  code: string;
216
+ device: string;
217
+ location: string;
214
218
  }): Promise<any>;
215
219
  signInSSO({ redirect_uri, state, client_id, response_type, path, }: {
216
220
  redirect_uri: string;
@@ -219,6 +223,36 @@ declare const ViewService: {
219
223
  response_type: string;
220
224
  path: string;
221
225
  }): Promise<any>;
226
+ grantAccess({ redirect_uri, state, client_id, scopes, }: {
227
+ redirect_uri: string;
228
+ state: string;
229
+ client_id: string;
230
+ scopes: string[];
231
+ }): Promise<any>;
232
+ getFieldsViewSecurity({ method, token, views, }: {
233
+ method: string;
234
+ token: string;
235
+ views: any;
236
+ }): Promise<any>;
237
+ settingsWebRead2fa({ method, model, kwargs, token, }: {
238
+ method: string;
239
+ token: string;
240
+ kwargs: any;
241
+ model: string;
242
+ }): Promise<any>;
243
+ requestSetupTotp({ method, token }: {
244
+ method: string;
245
+ token: string;
246
+ }): Promise<any>;
247
+ verifyTotp({ method, action_token, code, }: {
248
+ method: string;
249
+ action_token: string;
250
+ code: string;
251
+ }): Promise<any>;
252
+ removeTotpSetUp({ method, token }: {
253
+ method: string;
254
+ token: string;
255
+ }): Promise<any>;
222
256
  };
223
257
 
224
258
  export { ActionService, AuthService, CompanyService, ExcelService, FormService, KanbanServices as KanbanService, ModelService, UserService, ViewService };
@@ -60,6 +60,8 @@ declare const AuthService: {
60
60
  access_token: string;
61
61
  }): Promise<any>;
62
62
  getProviders(db?: string): Promise<any>;
63
+ getAccessByCode(code: string): Promise<any>;
64
+ logout(data: string): Promise<any>;
63
65
  };
64
66
 
65
67
  declare const CompanyService: {
@@ -180,7 +182,7 @@ declare const ModelService: {
180
182
  };
181
183
 
182
184
  declare const UserService: {
183
- getProfile(): Promise<any>;
185
+ getProfile(path?: string): Promise<any>;
184
186
  getUser({ context, id }: {
185
187
  context: any;
186
188
  id: any;
@@ -207,10 +209,12 @@ declare const ViewService: {
207
209
  method: string;
208
210
  with_context: any;
209
211
  }): Promise<any>;
210
- verify2FA({ method, with_context, code, }: {
212
+ verify2FA({ method, with_context, code, device, location, }: {
211
213
  method: string;
212
214
  with_context: any;
213
215
  code: string;
216
+ device: string;
217
+ location: string;
214
218
  }): Promise<any>;
215
219
  signInSSO({ redirect_uri, state, client_id, response_type, path, }: {
216
220
  redirect_uri: string;
@@ -219,6 +223,36 @@ declare const ViewService: {
219
223
  response_type: string;
220
224
  path: string;
221
225
  }): Promise<any>;
226
+ grantAccess({ redirect_uri, state, client_id, scopes, }: {
227
+ redirect_uri: string;
228
+ state: string;
229
+ client_id: string;
230
+ scopes: string[];
231
+ }): Promise<any>;
232
+ getFieldsViewSecurity({ method, token, views, }: {
233
+ method: string;
234
+ token: string;
235
+ views: any;
236
+ }): Promise<any>;
237
+ settingsWebRead2fa({ method, model, kwargs, token, }: {
238
+ method: string;
239
+ token: string;
240
+ kwargs: any;
241
+ model: string;
242
+ }): Promise<any>;
243
+ requestSetupTotp({ method, token }: {
244
+ method: string;
245
+ token: string;
246
+ }): Promise<any>;
247
+ verifyTotp({ method, action_token, code, }: {
248
+ method: string;
249
+ action_token: string;
250
+ code: string;
251
+ }): Promise<any>;
252
+ removeTotpSetUp({ method, token }: {
253
+ method: string;
254
+ token: string;
255
+ }): Promise<any>;
222
256
  };
223
257
 
224
258
  export { ActionService, AuthService, CompanyService, ExcelService, FormService, KanbanServices as KanbanService, ModelService, UserService, ViewService };