@litianxiang/portal-core 0.1.19 → 0.1.20

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/index.d.ts CHANGED
@@ -52,14 +52,14 @@ interface InactivityResult {
52
52
  declare function calcInactivityAction(lastActiveTime: number | null | undefined, now: number, config?: InactivityConfig): InactivityResult;
53
53
 
54
54
  interface CreateAuthHttpClientOptions {
55
- axios: any;
55
+ axios?: any;
56
56
  baseURL?: string;
57
57
  timeout?: number;
58
58
  getUserStore: () => any;
59
59
  getLoadingStore: () => any;
60
60
  authLoginUrl?: string;
61
61
  ssoStorageKey?: string;
62
- refreshUrl: string;
62
+ refreshUrl?: string;
63
63
  inactiveExpireMs?: number;
64
64
  inactiveBufferMs?: number;
65
65
  onShowError?: (msg: string) => void;
package/dist/index.js CHANGED
@@ -223,6 +223,24 @@ function calcInactivityAction(lastActiveTime, now, config = {}) {
223
223
  };
224
224
  }
225
225
 
226
+ // src/http/http.ts
227
+ import axiosLib from "axios";
228
+
229
+ // src/config/auth-config.ts
230
+ var DEFAULT_SSO_STORAGE_KEY = "user-store";
231
+ var DEFAULT_AUTH_LOGIN_ENV_KEY = "VITE_AUTH_LOGIN_URL";
232
+ var DEFAULT_AUTH_LOGIN_PATH = "/auth/#/login";
233
+ function getDefaultAuthLoginUrl() {
234
+ if (typeof window === "undefined") return "";
235
+ const origin = window.location.origin || "";
236
+ return `${origin}${DEFAULT_AUTH_LOGIN_PATH}`;
237
+ }
238
+ var AUTH_CONFIG = {
239
+ ssoStorageKey: DEFAULT_SSO_STORAGE_KEY,
240
+ authLoginEnvKey: DEFAULT_AUTH_LOGIN_ENV_KEY,
241
+ authLoginPath: DEFAULT_AUTH_LOGIN_PATH
242
+ };
243
+
226
244
  // src/http/http.ts
227
245
  function createAuthHttpClient(options) {
228
246
  const {
@@ -232,20 +250,22 @@ function createAuthHttpClient(options) {
232
250
  getUserStore,
233
251
  getLoadingStore,
234
252
  authLoginUrl,
235
- ssoStorageKey = "user-store",
236
- refreshUrl,
253
+ ssoStorageKey = AUTH_CONFIG.ssoStorageKey,
254
+ refreshUrl = "/proxy/auth/api/token/refresh",
237
255
  inactiveExpireMs,
238
256
  inactiveBufferMs,
239
257
  onShowError
240
258
  } = options;
241
- const http = axios.create({
259
+ const axiosInstance = axios || axiosLib;
260
+ const resolvedAuthLoginUrl = authLoginUrl || import.meta?.env?.[AUTH_CONFIG.authLoginEnvKey] || getDefaultAuthLoginUrl();
261
+ const http = axiosInstance.create({
242
262
  baseURL,
243
263
  timeout
244
264
  });
245
265
  const logoutToAuth = createLogoutToAuth({
246
266
  getUserStore,
247
267
  getLoadingStore,
248
- authLoginUrl,
268
+ authLoginUrl: resolvedAuthLoginUrl,
249
269
  ssoStorageKey
250
270
  });
251
271
  let isRefreshing = false;
@@ -275,7 +295,7 @@ function createAuthHttpClient(options) {
275
295
  if (shouldRefresh && !isRefreshing) {
276
296
  isRefreshing = true;
277
297
  try {
278
- const response = await axios.post(refreshUrl, {}, {
298
+ const response = await axiosInstance.post(refreshUrl, {}, {
279
299
  headers: { Authorization: `Bearer ${refreshToken}` }
280
300
  });
281
301
  const result = response.data;
@@ -842,21 +862,6 @@ function createLoadingStoreOptions() {
842
862
  }
843
863
  };
844
864
  }
845
-
846
- // src/config/auth-config.ts
847
- var DEFAULT_SSO_STORAGE_KEY = "user-store";
848
- var DEFAULT_AUTH_LOGIN_ENV_KEY = "VITE_AUTH_LOGIN_URL";
849
- var DEFAULT_AUTH_LOGIN_PATH = "/auth/#/login";
850
- function getDefaultAuthLoginUrl() {
851
- if (typeof window === "undefined") return "";
852
- const origin = window.location.origin || "";
853
- return `${origin}${DEFAULT_AUTH_LOGIN_PATH}`;
854
- }
855
- var AUTH_CONFIG = {
856
- ssoStorageKey: DEFAULT_SSO_STORAGE_KEY,
857
- authLoginEnvKey: DEFAULT_AUTH_LOGIN_ENV_KEY,
858
- authLoginPath: DEFAULT_AUTH_LOGIN_PATH
859
- };
860
865
  export {
861
866
  AUTH_CONFIG,
862
867
  DEFAULT_AUTH_LOGIN_ENV_KEY,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litianxiang/portal-core",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -17,6 +17,9 @@
17
17
  "vue-router": "^4.5.0",
18
18
  "dayjs": "^1.11.0"
19
19
  },
20
+ "dependencies": {
21
+ "axios": "^1.8.4"
22
+ },
20
23
  "devDependencies": {
21
24
  "tsup": "^8.3.0",
22
25
  "typescript": "^5.6.3",