@fctc/interface-logic 1.7.1 → 1.7.3

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
@@ -43,13 +43,11 @@ 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
- db: "",
49
- refreshTokenEndpoint: "",
50
49
  config: null,
51
50
  envFile: null,
52
- requests: null,
53
51
  defaultCompany: {
54
52
  id: null,
55
53
  logo: "",
@@ -2846,16 +2844,19 @@ var axiosClient = {
2846
2844
  timeout: 5e4,
2847
2845
  paramsSerializer: (params) => new URLSearchParams(params).toString()
2848
2846
  });
2849
- instance.interceptors.request.use(async (config2) => {
2850
- const { useRefreshToken, useActionToken, actionToken } = config2;
2851
- if (useActionToken && actionToken) {
2852
- config2.headers["Action-Token"] = actionToken;
2853
- }
2854
- const getToken = useRefreshToken ? localStorage2.getRefreshToken : localStorage2.getAccessToken;
2855
- const token = await getToken?.();
2856
- if (token) config2.headers["Authorization"] = `Bearer ${token}`;
2857
- return config2;
2858
- }, Promise.reject);
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
+ );
2859
2860
  instance.interceptors.response.use(
2860
2861
  (response) => {
2861
2862
  return handleResponse(response);
@@ -2996,7 +2997,9 @@ var axiosClient = {
2996
2997
  };
2997
2998
 
2998
2999
  // src/environment/EnvStore.ts
2999
- var EnvStore = class {
3000
+ var EnvStore = class _EnvStore {
3001
+ static instance = null;
3002
+ envStore;
3000
3003
  baseUrl;
3001
3004
  requests;
3002
3005
  context;
@@ -3008,76 +3011,83 @@ var EnvStore = class {
3008
3011
  localStorageUtils;
3009
3012
  sessionStorageUtils;
3010
3013
  refreshTokenEndpoint;
3011
- constructor(localStorageUtils2, sessionStorageUtils2) {
3014
+ constructor(envStore2, localStorageUtils2, sessionStorageUtils2) {
3015
+ this.envStore = envStore2;
3012
3016
  this.localStorageUtils = localStorageUtils2;
3013
3017
  this.sessionStorageUtils = sessionStorageUtils2;
3014
3018
  this.setup();
3015
3019
  }
3020
+ static getInstance(envStore2, localStorageUtils2, sessionStorageUtils2) {
3021
+ if (!_EnvStore.instance) {
3022
+ _EnvStore.instance = new _EnvStore(
3023
+ envStore2,
3024
+ localStorageUtils2,
3025
+ sessionStorageUtils2
3026
+ );
3027
+ }
3028
+ return _EnvStore.instance;
3029
+ }
3016
3030
  setup() {
3017
- const env2 = envStore.getState().env;
3018
- this.baseUrl = env2?.baseUrl;
3019
- this.context = env2?.context;
3020
- this.defaultCompany = env2?.defaultCompany;
3021
- this.config = env2?.config;
3022
- this.companies = env2?.companies || [];
3023
- this.user = env2?.user;
3024
- this.db = env2?.db;
3025
- this.requests = env2?.requests;
3026
- this.refreshTokenEndpoint = env2?.refreshTokenEndpoint;
3031
+ const env = this.envStore.getState().env;
3032
+ this.baseUrl = env?.baseUrl;
3033
+ this.requests = env?.requests;
3034
+ this.context = env?.context;
3035
+ this.defaultCompany = env?.defaultCompany;
3036
+ this.config = env?.config;
3037
+ this.companies = env?.companies || [];
3038
+ this.user = env?.user;
3039
+ this.db = env?.db;
3040
+ this.refreshTokenEndpoint = env?.refreshTokenEndpoint;
3041
+ console.log("Env setup:", this);
3027
3042
  }
3028
3043
  setupEnv(envConfig) {
3029
- let env2 = {
3044
+ const dispatch = this.envStore.dispatch;
3045
+ const env = {
3030
3046
  ...envConfig,
3031
3047
  localStorageUtils: this.localStorageUtils,
3032
3048
  sessionStorageUtils: this.sessionStorageUtils
3033
3049
  };
3034
- const requests = axiosClient.init(env2);
3035
- this.requests = requests;
3036
- const dispatch = envStore.dispatch;
3037
- dispatch(
3038
- setEnv({
3039
- ...env2,
3040
- requests
3041
- })
3042
- );
3050
+ const requests = axiosClient.init(env);
3051
+ dispatch(setEnv({ ...env, requests }));
3043
3052
  this.setup();
3044
- return { ...env2, requests };
3045
3053
  }
3046
3054
  setUid(uid) {
3047
- const dispatch = envStore.dispatch;
3055
+ const dispatch = this.envStore.dispatch;
3048
3056
  dispatch(setUid(uid));
3049
3057
  this.setup();
3050
3058
  }
3051
3059
  setLang(lang) {
3052
- const dispatch = envStore.dispatch;
3060
+ const dispatch = this.envStore.dispatch;
3053
3061
  dispatch(setLang(lang));
3054
3062
  this.setup();
3055
3063
  }
3056
3064
  setAllowCompanies(allowCompanies) {
3057
- const dispatch = envStore.dispatch;
3065
+ const dispatch = this.envStore.dispatch;
3058
3066
  dispatch(setAllowCompanies(allowCompanies));
3059
3067
  this.setup();
3060
3068
  }
3061
3069
  setCompanies(companies) {
3062
- const dispatch = envStore.dispatch;
3070
+ const dispatch = this.envStore.dispatch;
3063
3071
  dispatch(setCompanies(companies));
3064
3072
  this.setup();
3065
3073
  }
3066
3074
  setDefaultCompany(company) {
3067
- const dispatch = envStore.dispatch;
3075
+ const dispatch = this.envStore.dispatch;
3068
3076
  dispatch(setDefaultCompany(company));
3069
3077
  this.setup();
3070
3078
  }
3071
3079
  setUserInfo(userInfo) {
3072
- const dispatch = envStore.dispatch;
3080
+ const dispatch = this.envStore.dispatch;
3073
3081
  dispatch(setUser(userInfo));
3074
3082
  this.setup();
3075
3083
  }
3076
3084
  };
3077
- var env = null;
3078
3085
  function getEnv() {
3079
- if (!env) env = new EnvStore(localStorageUtils(), sessionStorageUtils());
3080
- return env;
3086
+ const instance = EnvStore.getInstance(envStore);
3087
+ if (!instance) {
3088
+ throw new Error("EnvStore has not been initialized \u2014 call initEnv() first");
3089
+ }
3090
+ return instance;
3081
3091
  }
3082
3092
 
3083
3093
  // src/services/view-service/index.ts
@@ -3089,7 +3099,7 @@ var ViewService = {
3089
3099
  options = {},
3090
3100
  aid
3091
3101
  }) {
3092
- const env2 = getEnv();
3102
+ const env = getEnv();
3093
3103
  const defaultOptions = {
3094
3104
  load_filters: true,
3095
3105
  toolbar: true,
@@ -3104,14 +3114,14 @@ var ViewService = {
3104
3114
  },
3105
3115
  with_context: context
3106
3116
  };
3107
- return env2?.requests?.post("/call" /* CALL_PATH */, jsonDataView, {
3117
+ return env?.requests?.post("/call" /* CALL_PATH */, jsonDataView, {
3108
3118
  headers: {
3109
3119
  "Content-Type": "application/json"
3110
3120
  }
3111
3121
  });
3112
3122
  },
3113
3123
  async getMenu(context) {
3114
- const env2 = getEnv();
3124
+ const env = getEnv();
3115
3125
  const jsonData = {
3116
3126
  model: "ir.ui.menu" /* MENU */,
3117
3127
  method: "web_search_read" /* WEB_SEARCH_READ */,
@@ -3248,14 +3258,14 @@ var ViewService = {
3248
3258
  ]
3249
3259
  }
3250
3260
  };
3251
- return env2?.requests?.post("/call" /* CALL_PATH */, jsonData, {
3261
+ return env?.requests?.post("/call" /* CALL_PATH */, jsonData, {
3252
3262
  headers: {
3253
3263
  "Content-Type": "application/json"
3254
3264
  }
3255
3265
  });
3256
3266
  },
3257
3267
  async getActionDetail(aid, context) {
3258
- const env2 = getEnv();
3268
+ const env = getEnv();
3259
3269
  const jsonData = {
3260
3270
  model: "ir.actions.act_window" /* WINDOW_ACTION */,
3261
3271
  method: "web_read" /* WEB_READ */,
@@ -3276,7 +3286,7 @@ var ViewService = {
3276
3286
  }
3277
3287
  }
3278
3288
  };
3279
- return env2?.requests?.post("/call" /* CALL_PATH */, jsonData, {
3289
+ return env?.requests?.post("/call" /* CALL_PATH */, jsonData, {
3280
3290
  headers: {
3281
3291
  "Content-Type": "application/json"
3282
3292
  }
@@ -3288,7 +3298,7 @@ var ViewService = {
3288
3298
  context,
3289
3299
  offset
3290
3300
  }) {
3291
- const env2 = getEnv();
3301
+ const env = getEnv();
3292
3302
  const jsonData = {
3293
3303
  model,
3294
3304
  with_context: context,
@@ -3296,14 +3306,14 @@ var ViewService = {
3296
3306
  field: "sequence",
3297
3307
  ...offset > 0 ? { offset } : {}
3298
3308
  };
3299
- return env2?.requests.post("/web/dataset/resequence", jsonData, {
3309
+ return env?.requests.post("/web/dataset/resequence", jsonData, {
3300
3310
  headers: {
3301
3311
  "Content-Type": "application/json"
3302
3312
  }
3303
3313
  });
3304
3314
  },
3305
3315
  async getSelectionItem({ data }) {
3306
- const env2 = getEnv();
3316
+ const env = getEnv();
3307
3317
  const jsonData = {
3308
3318
  model: data.model,
3309
3319
  ids: [],
@@ -3321,15 +3331,15 @@ var ViewService = {
3321
3331
  }
3322
3332
  }
3323
3333
  };
3324
- return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3334
+ return env?.requests.post("/call" /* CALL_PATH */, jsonData, {
3325
3335
  headers: {
3326
3336
  "Content-Type": "application/json"
3327
3337
  }
3328
3338
  });
3329
3339
  },
3330
3340
  async loadMessages() {
3331
- const env2 = getEnv();
3332
- return env2.requests.post(
3341
+ const env = getEnv();
3342
+ return env.requests.post(
3333
3343
  "/load_message_failures" /* LOAD_MESSAGE */,
3334
3344
  {},
3335
3345
  {
@@ -3340,8 +3350,9 @@ var ViewService = {
3340
3350
  );
3341
3351
  },
3342
3352
  async getVersion() {
3343
- const env2 = getEnv();
3344
- return env2?.requests.get("", {
3353
+ const env = getEnv();
3354
+ console.log("env?.requests", env, env?.requests);
3355
+ return env?.requests?.get("", {
3345
3356
  headers: {
3346
3357
  "Content-Type": "application/json"
3347
3358
  }
@@ -3351,12 +3362,12 @@ var ViewService = {
3351
3362
  method,
3352
3363
  with_context
3353
3364
  }) {
3354
- const env2 = getEnv();
3365
+ const env = getEnv();
3355
3366
  const jsonData = {
3356
3367
  method,
3357
3368
  with_context
3358
3369
  };
3359
- return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3370
+ return env?.requests.post("/call" /* CALL_PATH */, jsonData, {
3360
3371
  headers: {
3361
3372
  "Content-Type": "application/json"
3362
3373
  }
@@ -3369,7 +3380,7 @@ var ViewService = {
3369
3380
  device,
3370
3381
  location
3371
3382
  }) {
3372
- const env2 = getEnv();
3383
+ const env = getEnv();
3373
3384
  const jsonData = {
3374
3385
  method,
3375
3386
  kwargs: {
@@ -3381,7 +3392,7 @@ var ViewService = {
3381
3392
  },
3382
3393
  with_context
3383
3394
  };
3384
- return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3395
+ return env?.requests.post("/call" /* CALL_PATH */, jsonData, {
3385
3396
  headers: {
3386
3397
  "Content-Type": "application/json"
3387
3398
  },
@@ -3395,7 +3406,7 @@ var ViewService = {
3395
3406
  response_type,
3396
3407
  path
3397
3408
  }) {
3398
- const env2 = getEnv();
3409
+ const env = getEnv();
3399
3410
  const params = new URLSearchParams({
3400
3411
  response_type,
3401
3412
  client_id,
@@ -3403,7 +3414,7 @@ var ViewService = {
3403
3414
  state
3404
3415
  });
3405
3416
  const url = `${path}?${params.toString()}`;
3406
- return env2?.requests.get(url, {
3417
+ return env?.requests.get(url, {
3407
3418
  headers: {
3408
3419
  "Content-Type": "application/json"
3409
3420
  },
@@ -3416,14 +3427,14 @@ var ViewService = {
3416
3427
  client_id,
3417
3428
  scopes
3418
3429
  }) {
3419
- const env2 = getEnv();
3430
+ const env = getEnv();
3420
3431
  const jsonData = {
3421
3432
  redirect_uri,
3422
3433
  state,
3423
3434
  client_id,
3424
3435
  scopes
3425
3436
  };
3426
- return env2?.requests.post("/grant-access" /* GRANT_ACCESS */, jsonData, {
3437
+ return env?.requests.post("/grant-access" /* GRANT_ACCESS */, jsonData, {
3427
3438
  headers: {
3428
3439
  "Content-Type": "application/json"
3429
3440
  },
@@ -3435,7 +3446,7 @@ var ViewService = {
3435
3446
  token,
3436
3447
  views
3437
3448
  }) {
3438
- const env2 = getEnv();
3449
+ const env = getEnv();
3439
3450
  const jsonData = {
3440
3451
  method,
3441
3452
  kwargs: {
@@ -3445,7 +3456,7 @@ var ViewService = {
3445
3456
  token
3446
3457
  }
3447
3458
  };
3448
- return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3459
+ return env?.requests.post("/call" /* CALL_PATH */, jsonData, {
3449
3460
  headers: {
3450
3461
  "Content-Type": "application/json"
3451
3462
  }
@@ -3457,7 +3468,7 @@ var ViewService = {
3457
3468
  kwargs,
3458
3469
  token
3459
3470
  }) {
3460
- const env2 = getEnv();
3471
+ const env = getEnv();
3461
3472
  const jsonData = {
3462
3473
  method,
3463
3474
  model,
@@ -3466,21 +3477,21 @@ var ViewService = {
3466
3477
  token
3467
3478
  }
3468
3479
  };
3469
- return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3480
+ return env?.requests.post("/call" /* CALL_PATH */, jsonData, {
3470
3481
  headers: {
3471
3482
  "Content-Type": "application/json"
3472
3483
  }
3473
3484
  });
3474
3485
  },
3475
3486
  async requestSetupTotp({ method, token }) {
3476
- const env2 = getEnv();
3487
+ const env = getEnv();
3477
3488
  const jsonData = {
3478
3489
  method,
3479
3490
  with_context: {
3480
3491
  token
3481
3492
  }
3482
3493
  };
3483
- return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3494
+ return env?.requests.post("/call" /* CALL_PATH */, jsonData, {
3484
3495
  headers: {
3485
3496
  "Content-Type": "application/json"
3486
3497
  }
@@ -3491,7 +3502,7 @@ var ViewService = {
3491
3502
  action_token,
3492
3503
  code
3493
3504
  }) {
3494
- const env2 = getEnv();
3505
+ const env = getEnv();
3495
3506
  const jsonData = {
3496
3507
  method,
3497
3508
  kwargs: {
@@ -3503,21 +3514,21 @@ var ViewService = {
3503
3514
  action_token
3504
3515
  }
3505
3516
  };
3506
- return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3517
+ return env?.requests.post("/call" /* CALL_PATH */, jsonData, {
3507
3518
  headers: {
3508
3519
  "Content-Type": "application/json"
3509
3520
  }
3510
3521
  });
3511
3522
  },
3512
3523
  async removeTotpSetUp({ method, token }) {
3513
- const env2 = getEnv();
3524
+ const env = getEnv();
3514
3525
  const jsonData = {
3515
3526
  method,
3516
3527
  with_context: {
3517
3528
  token
3518
3529
  }
3519
3530
  };
3520
- return env2?.requests.post("/call" /* CALL_PATH */, jsonData, {
3531
+ return env?.requests.post("/call" /* CALL_PATH */, jsonData, {
3521
3532
  headers: {
3522
3533
  "Content-Type": "application/json"
3523
3534
  }
@@ -3538,6 +3549,7 @@ var VersionGate = ({ children }) => {
3538
3549
  };
3539
3550
  const validateVersion = async () => {
3540
3551
  const serverVersion = await view_service_default.getVersion();
3552
+ console.log("serverVersion", serverVersion);
3541
3553
  const cached = localStorage.getItem("__api_version__");
3542
3554
  if (cached !== serverVersion?.api_version) {
3543
3555
  clearVersion();
@@ -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;
@@ -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;