@fctc/interface-logic 1.7.4 → 1.7.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.
@@ -1,5 +1,8 @@
1
+ import { EnvStore } from './environment.mjs';
2
+ import '@reduxjs/toolkit';
3
+
1
4
  declare const axiosClient: {
2
- init(config: any): {
5
+ init(config: EnvStore): {
3
6
  get: (url: string, headers: any) => Promise<any>;
4
7
  post: (url: string, body: any, headers: any) => Promise<any>;
5
8
  post_excel: (url: string, body: any, headers: any) => Promise<any>;
package/dist/configs.d.ts CHANGED
@@ -1,5 +1,8 @@
1
+ import { EnvStore } from './environment.js';
2
+ import '@reduxjs/toolkit';
3
+
1
4
  declare const axiosClient: {
2
- init(config: any): {
5
+ init(config: EnvStore): {
3
6
  get: (url: string, headers: any) => Promise<any>;
4
7
  post: (url: string, body: any, headers: any) => Promise<any>;
5
8
  post_excel: (url: string, body: any, headers: any) => Promise<any>;
package/dist/configs.js CHANGED
@@ -2229,16 +2229,19 @@ var axiosClient = {
2229
2229
  timeout: 5e4,
2230
2230
  paramsSerializer: (params) => new URLSearchParams(params).toString()
2231
2231
  });
2232
- instance.interceptors.request.use(async (config2) => {
2233
- const { useRefreshToken, useActionToken, actionToken } = config2;
2234
- if (useActionToken && actionToken) {
2235
- config2.headers["Action-Token"] = actionToken;
2232
+ instance.interceptors.request.use(
2233
+ async (config2) => {
2234
+ const useRefreshToken = config2.useRefreshToken;
2235
+ const token = useRefreshToken ? await localStorage2.getRefreshToken() : await localStorage2.getAccessToken();
2236
+ if (token) {
2237
+ config2.headers["Authorization"] = "Bearer " + token;
2238
+ }
2239
+ return config2;
2240
+ },
2241
+ (error) => {
2242
+ Promise.reject(error);
2236
2243
  }
2237
- const getToken = useRefreshToken ? localStorage2.getRefreshToken : localStorage2.getAccessToken;
2238
- const token = await getToken?.();
2239
- if (token) config2.headers["Authorization"] = `Bearer ${token}`;
2240
- return config2;
2241
- }, Promise.reject);
2244
+ );
2242
2245
  instance.interceptors.response.use(
2243
2246
  (response) => {
2244
2247
  return handleResponse(response);
package/dist/configs.mjs CHANGED
@@ -2193,16 +2193,19 @@ var axiosClient = {
2193
2193
  timeout: 5e4,
2194
2194
  paramsSerializer: (params) => new URLSearchParams(params).toString()
2195
2195
  });
2196
- instance.interceptors.request.use(async (config2) => {
2197
- const { useRefreshToken, useActionToken, actionToken } = config2;
2198
- if (useActionToken && actionToken) {
2199
- config2.headers["Action-Token"] = actionToken;
2196
+ instance.interceptors.request.use(
2197
+ async (config2) => {
2198
+ const useRefreshToken = config2.useRefreshToken;
2199
+ const token = useRefreshToken ? await localStorage2.getRefreshToken() : await localStorage2.getAccessToken();
2200
+ if (token) {
2201
+ config2.headers["Authorization"] = "Bearer " + token;
2202
+ }
2203
+ return config2;
2204
+ },
2205
+ (error) => {
2206
+ Promise.reject(error);
2200
2207
  }
2201
- const getToken = useRefreshToken ? localStorage2.getRefreshToken : localStorage2.getAccessToken;
2202
- const token = await getToken?.();
2203
- if (token) config2.headers["Authorization"] = `Bearer ${token}`;
2204
- return config2;
2205
- }, Promise.reject);
2208
+ );
2206
2209
  instance.interceptors.response.use(
2207
2210
  (response) => {
2208
2211
  return handleResponse(response);
@@ -1,37 +1,57 @@
1
- declare function setupEnv(envConfig: any): void;
2
- declare function getEnv(): {
3
- baseUrl: string;
4
- companies: never[];
5
- user: {};
6
- db: string;
7
- refreshTokenEndpoint: string;
8
- config: {
9
- grantType: string;
10
- clientId: string;
11
- clientSecret: string;
12
- redirectUri: string;
13
- };
14
- envFile: null;
15
- requests: {
16
- get: (url: string, headers?: any) => Promise<any>;
17
- post: (url: string, body: any, headers?: any) => Promise<any>;
18
- post_excel: (url: string, body: any, headers?: any) => Promise<any>;
19
- put: (url: string, body: any, headers?: any) => Promise<any>;
20
- patch: (url: string, body: any) => Promise<any>;
21
- delete: (url: string, body: any) => Promise<any>;
22
- };
23
- defaultCompany: {
24
- id: null;
25
- logo: string;
26
- secondary_color: string;
27
- primary_color: string;
28
- };
29
- context: {
30
- uid: null;
31
- allowed_company_ids: never[];
32
- lang: string;
33
- tz: string;
34
- };
1
+ import { EnhancedStore } from '@reduxjs/toolkit';
2
+
3
+ declare const localStorageUtils: () => {
4
+ setToken: (access_token: string) => Promise<void>;
5
+ setRefreshToken: (refresh_token: string) => Promise<void>;
6
+ getAccessToken: () => Promise<string | null>;
7
+ getRefreshToken: () => Promise<string | null>;
8
+ clearToken: () => Promise<void>;
9
+ };
10
+ type LocalStorageUtilsType = ReturnType<typeof localStorageUtils>;
11
+
12
+ declare const sessionStorageUtils: () => {
13
+ getBrowserSession: () => Promise<string | null>;
35
14
  };
15
+ type SessionStorageUtilsType = ReturnType<typeof sessionStorageUtils>;
16
+
17
+ declare global {
18
+ interface Global {
19
+ envStore?: EnvStore;
20
+ }
21
+ interface Window {
22
+ envStore?: EnvStore;
23
+ }
24
+ }
25
+ declare class EnvStore {
26
+ private static instance;
27
+ envStore: EnhancedStore | any;
28
+ baseUrl?: string;
29
+ requests?: any;
30
+ context?: any;
31
+ defaultCompany?: any;
32
+ config?: any;
33
+ companies?: any[];
34
+ user?: any;
35
+ db?: string;
36
+ localStorageUtils?: any;
37
+ sessionStorageUtils?: any;
38
+ refreshTokenEndpoint?: string;
39
+ private constructor();
40
+ static getInstance(envStore: EnhancedStore, localStorageUtils?: any, sessionStorageUtils?: any): EnvStore;
41
+ setup(): void;
42
+ setupEnv(envConfig: Partial<EnvStore>): void;
43
+ setUid(uid: number): void;
44
+ setLang(lang: string): void;
45
+ setAllowCompanies(allowCompanies: number[]): void;
46
+ setCompanies(companies: any[]): void;
47
+ setDefaultCompany(company: any): void;
48
+ setUserInfo(userInfo: any): void;
49
+ }
50
+ declare function initEnv({ envStore, localStorageUtils, sessionStorageUtils, }: {
51
+ envStore: EnhancedStore;
52
+ localStorageUtils?: LocalStorageUtilsType;
53
+ sessionStorageUtils?: SessionStorageUtilsType;
54
+ }): EnvStore;
55
+ declare function getEnv(): EnvStore;
36
56
 
37
- export { getEnv, setupEnv };
57
+ export { EnvStore, getEnv, initEnv };
@@ -1,37 +1,57 @@
1
- declare function setupEnv(envConfig: any): void;
2
- declare function getEnv(): {
3
- baseUrl: string;
4
- companies: never[];
5
- user: {};
6
- db: string;
7
- refreshTokenEndpoint: string;
8
- config: {
9
- grantType: string;
10
- clientId: string;
11
- clientSecret: string;
12
- redirectUri: string;
13
- };
14
- envFile: null;
15
- requests: {
16
- get: (url: string, headers?: any) => Promise<any>;
17
- post: (url: string, body: any, headers?: any) => Promise<any>;
18
- post_excel: (url: string, body: any, headers?: any) => Promise<any>;
19
- put: (url: string, body: any, headers?: any) => Promise<any>;
20
- patch: (url: string, body: any) => Promise<any>;
21
- delete: (url: string, body: any) => Promise<any>;
22
- };
23
- defaultCompany: {
24
- id: null;
25
- logo: string;
26
- secondary_color: string;
27
- primary_color: string;
28
- };
29
- context: {
30
- uid: null;
31
- allowed_company_ids: never[];
32
- lang: string;
33
- tz: string;
34
- };
1
+ import { EnhancedStore } from '@reduxjs/toolkit';
2
+
3
+ declare const localStorageUtils: () => {
4
+ setToken: (access_token: string) => Promise<void>;
5
+ setRefreshToken: (refresh_token: string) => Promise<void>;
6
+ getAccessToken: () => Promise<string | null>;
7
+ getRefreshToken: () => Promise<string | null>;
8
+ clearToken: () => Promise<void>;
9
+ };
10
+ type LocalStorageUtilsType = ReturnType<typeof localStorageUtils>;
11
+
12
+ declare const sessionStorageUtils: () => {
13
+ getBrowserSession: () => Promise<string | null>;
35
14
  };
15
+ type SessionStorageUtilsType = ReturnType<typeof sessionStorageUtils>;
16
+
17
+ declare global {
18
+ interface Global {
19
+ envStore?: EnvStore;
20
+ }
21
+ interface Window {
22
+ envStore?: EnvStore;
23
+ }
24
+ }
25
+ declare class EnvStore {
26
+ private static instance;
27
+ envStore: EnhancedStore | any;
28
+ baseUrl?: string;
29
+ requests?: any;
30
+ context?: any;
31
+ defaultCompany?: any;
32
+ config?: any;
33
+ companies?: any[];
34
+ user?: any;
35
+ db?: string;
36
+ localStorageUtils?: any;
37
+ sessionStorageUtils?: any;
38
+ refreshTokenEndpoint?: string;
39
+ private constructor();
40
+ static getInstance(envStore: EnhancedStore, localStorageUtils?: any, sessionStorageUtils?: any): EnvStore;
41
+ setup(): void;
42
+ setupEnv(envConfig: Partial<EnvStore>): void;
43
+ setUid(uid: number): void;
44
+ setLang(lang: string): void;
45
+ setAllowCompanies(allowCompanies: number[]): void;
46
+ setCompanies(companies: any[]): void;
47
+ setDefaultCompany(company: any): void;
48
+ setUserInfo(userInfo: any): void;
49
+ }
50
+ declare function initEnv({ envStore, localStorageUtils, sessionStorageUtils, }: {
51
+ envStore: EnhancedStore;
52
+ localStorageUtils?: LocalStorageUtilsType;
53
+ sessionStorageUtils?: SessionStorageUtilsType;
54
+ }): EnvStore;
55
+ declare function getEnv(): EnvStore;
36
56
 
37
- export { getEnv, setupEnv };
57
+ export { EnvStore, getEnv, initEnv };