@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.
@@ -1,9 +1,9 @@
1
1
  declare const axiosClient: {
2
2
  init(config: any): {
3
- get: (url: string, headers?: any) => Promise<any>;
4
- post: (url: string, body: any, headers?: any) => Promise<any>;
5
- post_excel: (url: string, body: any, headers?: any) => Promise<any>;
6
- put: (url: string, body: any, headers?: any) => Promise<any>;
3
+ get: (url: string, headers: any) => Promise<any>;
4
+ post: (url: string, body: any, headers: any) => Promise<any>;
5
+ post_excel: (url: string, body: any, headers: any) => Promise<any>;
6
+ put: (url: string, body: any, headers: any) => Promise<any>;
7
7
  patch: (url: string, body: any) => Promise<any>;
8
8
  delete: (url: string, body: any) => Promise<any>;
9
9
  };
package/dist/configs.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  declare const axiosClient: {
2
2
  init(config: any): {
3
- get: (url: string, headers?: any) => Promise<any>;
4
- post: (url: string, body: any, headers?: any) => Promise<any>;
5
- post_excel: (url: string, body: any, headers?: any) => Promise<any>;
6
- put: (url: string, body: any, headers?: any) => Promise<any>;
3
+ get: (url: string, headers: any) => Promise<any>;
4
+ post: (url: string, body: any, headers: any) => Promise<any>;
5
+ post_excel: (url: string, body: any, headers: any) => Promise<any>;
6
+ put: (url: string, body: any, headers: any) => Promise<any>;
7
7
  patch: (url: string, body: any) => Promise<any>;
8
8
  delete: (url: string, body: any) => Promise<any>;
9
9
  };
package/dist/configs.js CHANGED
@@ -2208,9 +2208,9 @@ var sessionStorageUtils = () => {
2208
2208
  // src/configs/axios-client.ts
2209
2209
  var axiosClient = {
2210
2210
  init(config) {
2211
- const localStorage2 = config.localStorageUtils ?? localStorageUtils();
2212
- const sessionStorage2 = config.sessionStorageUtils ?? sessionStorageUtils();
2213
- const db = config.db;
2211
+ const localStorage2 = config?.localStorageUtils ?? localStorageUtils();
2212
+ const sessionStorage2 = config?.sessionStorageUtils ?? sessionStorageUtils();
2213
+ const db = config?.db;
2214
2214
  let isRefreshing = false;
2215
2215
  let failedQueue = [];
2216
2216
  const processQueue = (error, token = null) => {
@@ -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
@@ -2172,9 +2172,9 @@ var sessionStorageUtils = () => {
2172
2172
  // src/configs/axios-client.ts
2173
2173
  var axiosClient = {
2174
2174
  init(config) {
2175
- const localStorage2 = config.localStorageUtils ?? localStorageUtils();
2176
- const sessionStorage2 = config.sessionStorageUtils ?? sessionStorageUtils();
2177
- const db = config.db;
2175
+ const localStorage2 = config?.localStorageUtils ?? localStorageUtils();
2176
+ const sessionStorage2 = config?.sessionStorageUtils ?? sessionStorageUtils();
2177
+ const db = config?.db;
2178
2178
  let isRefreshing = false;
2179
2179
  let failedQueue = [];
2180
2180
  const processQueue = (error, token = null) => {
@@ -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,58 @@
1
- declare function setupEnv(envConfig: any): any;
2
- declare function getEnv(): {
3
- requests: {
4
- get: (url: string, headers?: any) => Promise<any>;
5
- post: (url: string, body: any, headers?: any) => Promise<any>;
6
- post_excel: (url: string, body: any, headers?: any) => Promise<any>;
7
- put: (url: string, body: any, headers?: any) => Promise<any>;
8
- patch: (url: string, body: any) => Promise<any>;
9
- delete: (url: string, body: any) => Promise<any>;
10
- };
11
- baseUrl: string;
12
- companies: never[];
13
- user: {};
14
- db: string;
15
- refreshTokenEndpoint: string;
16
- config: {
17
- grantType: string;
18
- clientId: string;
19
- clientSecret: string;
20
- redirectUri: string;
21
- };
22
- envFile: null;
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
+ declare const localStorageUtils: () => {
2
+ setToken: (access_token: string) => Promise<void>;
3
+ setRefreshToken: (refresh_token: string) => Promise<void>;
4
+ getAccessToken: () => Promise<string | null>;
5
+ getRefreshToken: () => Promise<string | null>;
6
+ clearToken: () => Promise<void>;
35
7
  };
8
+ type LocalStorageUtilsType = ReturnType<typeof localStorageUtils>;
36
9
 
37
- export { getEnv, setupEnv };
10
+ declare const sessionStorageUtils: () => {
11
+ getBrowserSession: () => Promise<string | null>;
12
+ };
13
+ type SessionStorageUtilsType = ReturnType<typeof sessionStorageUtils>;
14
+
15
+ declare global {
16
+ interface Global {
17
+ envStore?: EnvStore;
18
+ }
19
+ interface Window {
20
+ envStore?: EnvStore;
21
+ }
22
+ }
23
+ interface EnvState {
24
+ baseUrl?: string;
25
+ requests?: any;
26
+ context?: any;
27
+ defaultCompany?: any;
28
+ config?: any;
29
+ companies?: any[];
30
+ user?: any;
31
+ db?: string;
32
+ refreshTokenEndpoint?: string;
33
+ uid?: number;
34
+ lang?: string;
35
+ allowCompanies?: number[];
36
+ }
37
+ declare class EnvStore {
38
+ private static instance;
39
+ private static localStorageUtils?;
40
+ private static sessionStorageUtils?;
41
+ private constructor();
42
+ static getInstance(localStorageUtils?: any, sessionStorageUtils?: any): EnvStore;
43
+ static getState(): EnvState;
44
+ static setupEnv(envConfig: Partial<EnvState>): void;
45
+ static setUid(uid: number): void;
46
+ static setLang(lang: string): void;
47
+ static setAllowCompanies(allowCompanies: number[]): void;
48
+ static setCompanies(companies: any[]): void;
49
+ static setDefaultCompany(company: any): void;
50
+ static setUserInfo(userInfo: any): void;
51
+ }
52
+ declare function initEnv({ localStorageUtils, sessionStorageUtils, }: {
53
+ localStorageUtils?: LocalStorageUtilsType;
54
+ sessionStorageUtils?: SessionStorageUtilsType;
55
+ }): EnvStore;
56
+ declare function getEnv(): EnvState;
57
+
58
+ export { EnvStore, getEnv, initEnv };
@@ -1,37 +1,58 @@
1
- declare function setupEnv(envConfig: any): any;
2
- declare function getEnv(): {
3
- requests: {
4
- get: (url: string, headers?: any) => Promise<any>;
5
- post: (url: string, body: any, headers?: any) => Promise<any>;
6
- post_excel: (url: string, body: any, headers?: any) => Promise<any>;
7
- put: (url: string, body: any, headers?: any) => Promise<any>;
8
- patch: (url: string, body: any) => Promise<any>;
9
- delete: (url: string, body: any) => Promise<any>;
10
- };
11
- baseUrl: string;
12
- companies: never[];
13
- user: {};
14
- db: string;
15
- refreshTokenEndpoint: string;
16
- config: {
17
- grantType: string;
18
- clientId: string;
19
- clientSecret: string;
20
- redirectUri: string;
21
- };
22
- envFile: null;
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
+ declare const localStorageUtils: () => {
2
+ setToken: (access_token: string) => Promise<void>;
3
+ setRefreshToken: (refresh_token: string) => Promise<void>;
4
+ getAccessToken: () => Promise<string | null>;
5
+ getRefreshToken: () => Promise<string | null>;
6
+ clearToken: () => Promise<void>;
35
7
  };
8
+ type LocalStorageUtilsType = ReturnType<typeof localStorageUtils>;
36
9
 
37
- export { getEnv, setupEnv };
10
+ declare const sessionStorageUtils: () => {
11
+ getBrowserSession: () => Promise<string | null>;
12
+ };
13
+ type SessionStorageUtilsType = ReturnType<typeof sessionStorageUtils>;
14
+
15
+ declare global {
16
+ interface Global {
17
+ envStore?: EnvStore;
18
+ }
19
+ interface Window {
20
+ envStore?: EnvStore;
21
+ }
22
+ }
23
+ interface EnvState {
24
+ baseUrl?: string;
25
+ requests?: any;
26
+ context?: any;
27
+ defaultCompany?: any;
28
+ config?: any;
29
+ companies?: any[];
30
+ user?: any;
31
+ db?: string;
32
+ refreshTokenEndpoint?: string;
33
+ uid?: number;
34
+ lang?: string;
35
+ allowCompanies?: number[];
36
+ }
37
+ declare class EnvStore {
38
+ private static instance;
39
+ private static localStorageUtils?;
40
+ private static sessionStorageUtils?;
41
+ private constructor();
42
+ static getInstance(localStorageUtils?: any, sessionStorageUtils?: any): EnvStore;
43
+ static getState(): EnvState;
44
+ static setupEnv(envConfig: Partial<EnvState>): void;
45
+ static setUid(uid: number): void;
46
+ static setLang(lang: string): void;
47
+ static setAllowCompanies(allowCompanies: number[]): void;
48
+ static setCompanies(companies: any[]): void;
49
+ static setDefaultCompany(company: any): void;
50
+ static setUserInfo(userInfo: any): void;
51
+ }
52
+ declare function initEnv({ localStorageUtils, sessionStorageUtils, }: {
53
+ localStorageUtils?: LocalStorageUtilsType;
54
+ sessionStorageUtils?: SessionStorageUtilsType;
55
+ }): EnvStore;
56
+ declare function getEnv(): EnvState;
57
+
58
+ export { EnvStore, getEnv, initEnv };