@clownlee/cores 1.0.18 → 1.0.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.
@@ -1,55 +1,11 @@
1
1
  import { RequestInitConfig, HttpInstance } from '@clownlee/http';
2
2
 
3
- export default class Apis {
3
+ /**
4
+ * 子应用授权相关 API(登录/注册等已提取至 main-app views/auth)
5
+ */
6
+ export default class SubAppAuthApis {
4
7
  protected http: HttpInstance;
5
8
  constructor(config: RequestInitConfig | HttpInstance);
6
- /**
7
- * 用户登录 API
8
- * @param data 登录表单数据
9
- * @returns 用户信息和Token
10
- */
11
- login(data: any): Promise<any>;
12
- /**
13
- * 用户登出 API
14
- * @param data 登出数据,包含 userId、password、tenantId
15
- * @returns 登出结果
16
- */
17
- logout(data?: {
18
- userId?: string;
19
- password?: string;
20
- tenantId?: string;
21
- }): Promise<any>;
22
- /**
23
- * 用户注册 API
24
- * @param data 注册表单数据
25
- * @returns 用户信息和Token
26
- */
27
- register(data: any): Promise<any>;
28
- /**
29
- * 获取租户列表 API
30
- * @param type 租户类型:LOGIN(登录)或 REGISTER(注册)
31
- * @returns 租户列表
32
- */
33
- getTenants(type?: 'LOGIN' | 'REGISTER'): Promise<any>;
34
- /**
35
- * 获取授权码 API
36
- * @param token 一次性Token(JWT)
37
- * @returns 授权码
38
- */
39
- getAuthorizationCode(token: string): Promise<any>;
40
- /**
41
- * 获取AccessToken和RefreshToken API
42
- * @param code 授权码
43
- * @param token 一次性Token(JWT)
44
- * @returns AccessToken和RefreshToken
45
- */
46
- getAccessToken(code: string, token: string): Promise<any>;
47
- /**
48
- * Token 刷新 API
49
- * @param refreshToken RefreshToken
50
- * @returns 新的AccessToken
51
- */
52
- refreshToken(refreshToken: string): Promise<any>;
53
9
  /**
54
10
  * 获取子应用授权码 API
55
11
  * @param clientId 客户端ID
@@ -1,9 +1,9 @@
1
1
  import { default as MenuApis } from './menu';
2
- import { default as AuthApis } from './auth';
2
+ import { default as SubAppAuthApis } from './auth';
3
3
  import { default as AppUserApis } from './app-user';
4
4
  import { default as ClientApis } from './client';
5
5
  import { default as RoleApis } from './role';
6
6
  import { default as RolePermissionApis } from './role-permission';
7
7
  import { default as UserCenterApis } from './user-center';
8
8
 
9
- export { MenuApis, AuthApis, AppUserApis, ClientApis, RoleApis, RolePermissionApis, UserCenterApis, };
9
+ export { MenuApis, SubAppAuthApis, AppUserApis, ClientApis, RoleApis, RolePermissionApis, UserCenterApis, };
package/dist/index.js CHANGED
@@ -2651,11 +2651,14 @@ async function handleTokenRefresh(refreshConfig, store, refreshTokenFromResponse
2651
2651
  throw refreshError;
2652
2652
  }
2653
2653
  }
2654
+ const REDIRECT_TO_LOGIN_CODES = [2006, 2007, 2003, 2004, 2e3];
2655
+ const TOKEN_REFRESH_CODE = 2001;
2656
+ const TENANT_SUPER_ADMIN_FIRST_LOGIN_CODE = 2008;
2654
2657
  async function handleResponseInterceptor(response, store, refreshConfig) {
2655
2658
  var _a, _b;
2656
2659
  const responseData = response == null ? void 0 : response.data;
2657
2660
  const code = responseData == null ? void 0 : responseData.code;
2658
- if ([2006, 2007, 2003, 2004, 2e3].includes(code)) {
2661
+ if (REDIRECT_TO_LOGIN_CODES.includes(code)) {
2659
2662
  if (!response.request.responseURL.endsWith("login") && !response.request.responseURL.endsWith("register") && !response.request.responseURL.endsWith("register/tenants")) {
2660
2663
  window.parent.postMessage({
2661
2664
  type: "error",
@@ -2667,8 +2670,19 @@ async function handleResponseInterceptor(response, store, refreshConfig) {
2667
2670
  }, "*");
2668
2671
  }
2669
2672
  throw new Error(responseData == null ? void 0 : responseData.message);
2670
- } else if (code === 2001) {
2673
+ } else if (code === TOKEN_REFRESH_CODE) {
2671
2674
  const config = response.config;
2675
+ if (config._retry) {
2676
+ window.parent.postMessage({
2677
+ type: "error",
2678
+ data: JSON.stringify({
2679
+ code: responseData == null ? void 0 : responseData.code,
2680
+ message: responseData == null ? void 0 : responseData.message,
2681
+ action: "toLogin"
2682
+ })
2683
+ }, "*");
2684
+ throw new Error(responseData == null ? void 0 : responseData.message);
2685
+ }
2672
2686
  if (!refreshConfig || !store) {
2673
2687
  return response;
2674
2688
  }
@@ -2693,8 +2707,8 @@ async function handleResponseInterceptor(response, store, refreshConfig) {
2693
2707
  } catch (refreshError) {
2694
2708
  throw refreshError;
2695
2709
  }
2696
- } else if (code > 0) {
2697
- throw new Error(responseData == null ? void 0 : responseData.message);
2710
+ } else if (code > 0 && code !== TENANT_SUPER_ADMIN_FIRST_LOGIN_CODE) {
2711
+ throw new Error((responseData == null ? void 0 : responseData.message + 222) ?? "请求失败");
2698
2712
  }
2699
2713
  return response;
2700
2714
  }
@@ -2779,6 +2793,7 @@ class RequestServiceClass {
2779
2793
  * 通用请求方法
2780
2794
  */
2781
2795
  async request(config) {
2796
+ var _a;
2782
2797
  const instance = this.getInstance();
2783
2798
  const axiosConfig = {
2784
2799
  ...config,
@@ -2786,6 +2801,9 @@ class RequestServiceClass {
2786
2801
  cancelToken: config.cancelToken && "token" in config.cancelToken ? config.cancelToken.token : config.cancelToken
2787
2802
  };
2788
2803
  const response = await instance.request(axiosConfig);
2804
+ if ((_a = response.headers["content-type"]) == null ? void 0 : _a.includes("application/octet-stream")) {
2805
+ return response;
2806
+ }
2789
2807
  return response.data;
2790
2808
  }
2791
2809
  /**
@@ -2860,7 +2878,7 @@ function init(config) {
2860
2878
  service.init(config);
2861
2879
  return service;
2862
2880
  }
2863
- let Apis$6 = class Apis {
2881
+ let Apis$5 = class Apis {
2864
2882
  constructor(config) {
2865
2883
  __publicField(this, "http");
2866
2884
  this.http = config || init(config);
@@ -2942,85 +2960,11 @@ let Apis$6 = class Apis {
2942
2960
  return await this.http.post("/api/v1/app/menu/update", data);
2943
2961
  }
2944
2962
  };
2945
- let Apis$5 = class Apis2 {
2963
+ class SubAppAuthApis {
2946
2964
  constructor(config) {
2947
2965
  __publicField(this, "http");
2948
2966
  this.http = config || init(config);
2949
2967
  }
2950
- /**
2951
- * 用户登录 API
2952
- * @param data 登录表单数据
2953
- * @returns 用户信息和Token
2954
- */
2955
- async login(data) {
2956
- return await this.http.post("/api/v1/iam/auth/login", data);
2957
- }
2958
- /**
2959
- * 用户登出 API
2960
- * @param data 登出数据,包含 userId、password、tenantId
2961
- * @returns 登出结果
2962
- */
2963
- async logout(data) {
2964
- return await this.http.post("/api/v1/iam/auth/logout", data || {});
2965
- }
2966
- /**
2967
- * 用户注册 API
2968
- * @param data 注册表单数据
2969
- * @returns 用户信息和Token
2970
- */
2971
- async register(data) {
2972
- return await this.http.post("/api/v1/iam/auth/register", data);
2973
- }
2974
- /**
2975
- * 获取租户列表 API
2976
- * @param type 租户类型:LOGIN(登录)或 REGISTER(注册)
2977
- * @returns 租户列表
2978
- */
2979
- async getTenants(type = "LOGIN") {
2980
- return await this.http.post("/api/v1/iam/auth/register/tenants", {
2981
- type
2982
- });
2983
- }
2984
- /**
2985
- * 获取授权码 API
2986
- * @param token 一次性Token(JWT)
2987
- * @returns 授权码
2988
- */
2989
- async getAuthorizationCode(token) {
2990
- return await this.http.get("/api/v1/iam/oauth2/authorize", null, {
2991
- headers: {
2992
- Authorization: `Bearer ${token}`
2993
- }
2994
- });
2995
- }
2996
- /**
2997
- * 获取AccessToken和RefreshToken API
2998
- * @param code 授权码
2999
- * @param token 一次性Token(JWT)
3000
- * @returns AccessToken和RefreshToken
3001
- */
3002
- async getAccessToken(code, token) {
3003
- return await this.http.post("/api/v1/iam/oauth2/token", {
3004
- grantType: "login_code",
3005
- code
3006
- }, {
3007
- headers: {
3008
- Authorization: `Bearer ${token}`
3009
- }
3010
- });
3011
- }
3012
- /**
3013
- * Token 刷新 API
3014
- * @param refreshToken RefreshToken
3015
- * @returns 新的AccessToken
3016
- */
3017
- async refreshToken(refreshToken) {
3018
- return await this.http.post("/api/v1/iam/auth/refresh-token", null, {
3019
- headers: {
3020
- Authorization: `Bearer ${refreshToken}`
3021
- }
3022
- });
3023
- }
3024
2968
  /**
3025
2969
  * 获取子应用授权码 API
3026
2970
  * @param clientId 客户端ID
@@ -3048,8 +2992,8 @@ let Apis$5 = class Apis2 {
3048
2992
  redirectUri
3049
2993
  });
3050
2994
  }
3051
- };
3052
- let Apis$4 = class Apis3 {
2995
+ }
2996
+ let Apis$4 = class Apis2 {
3053
2997
  constructor(config) {
3054
2998
  __publicField(this, "http");
3055
2999
  this.http = config || init(config);
@@ -3119,7 +3063,7 @@ let Apis$4 = class Apis3 {
3119
3063
  return await this.http.post("/api/v1/app/user/assignRoles", data);
3120
3064
  }
3121
3065
  };
3122
- let Apis$3 = class Apis4 {
3066
+ let Apis$3 = class Apis3 {
3123
3067
  constructor(config) {
3124
3068
  __publicField(this, "http");
3125
3069
  this.http = config || init(config);
@@ -3205,7 +3149,7 @@ let Apis$3 = class Apis4 {
3205
3149
  });
3206
3150
  }
3207
3151
  };
3208
- let Apis$2 = class Apis5 {
3152
+ let Apis$2 = class Apis4 {
3209
3153
  constructor(config) {
3210
3154
  __publicField(this, "http");
3211
3155
  this.http = config || init(config);
@@ -3275,7 +3219,7 @@ let Apis$2 = class Apis5 {
3275
3219
  });
3276
3220
  }
3277
3221
  };
3278
- let Apis$1 = class Apis6 {
3222
+ let Apis$1 = class Apis5 {
3279
3223
  constructor(config) {
3280
3224
  __publicField(this, "http");
3281
3225
  this.http = config || init(config);
@@ -3306,7 +3250,7 @@ let Apis$1 = class Apis6 {
3306
3250
  return await this.http.post("/api/v1/app/permission/getPermission");
3307
3251
  }
3308
3252
  };
3309
- class Apis7 {
3253
+ class Apis6 {
3310
3254
  constructor(config) {
3311
3255
  __publicField(this, "http");
3312
3256
  this.http = config || init(config);
@@ -22064,12 +22008,11 @@ function formatDateTime(dateTime) {
22064
22008
  const initHttp = init;
22065
22009
  export {
22066
22010
  Apis$4 as AppUserApis,
22067
- Apis$5 as AuthApis,
22068
22011
  _sfc_main$5 as Breadcrumb,
22069
22012
  Apis$3 as ClientApis,
22070
22013
  index as CropImage,
22071
22014
  iconsSelect as IconsSelect,
22072
- Apis$6 as MenuApis,
22015
+ Apis$5 as MenuApis,
22073
22016
  PERMISSION_CHECKER_KEY,
22074
22017
  PERMISSION_STORE_KEY,
22075
22018
  _sfc_main$1 as PageContainer,
@@ -22080,7 +22023,8 @@ export {
22080
22023
  Apis$2 as RoleApis,
22081
22024
  Apis$1 as RolePermissionApis,
22082
22025
  selectLoadMore as SelectLoadMore,
22083
- Apis7 as UserCenterApis,
22026
+ SubAppAuthApis,
22027
+ Apis6 as UserCenterApis,
22084
22028
  checkMultiplePermissionsAND,
22085
22029
  checkMultiplePermissionsOR,
22086
22030
  checkPermission,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clownlee/cores",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "公共核心库,提供统一的 HTTP 请求能力和自动 token 刷新功能",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "author": "",
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "@clownlee/http": "^1.0.3",
33
+ "@clownlee/http": "^1.0.5",
34
34
  "pinia": "^2.1.7",
35
35
  "vue": "^3.5.25",
36
36
  "cropper": "^4.1.0",