@clownlee/cores 1.0.19 → 1.0.21

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.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { default as init } from '@clownlee/http';
2
2
 
3
3
  export declare const initHttp: typeof init;
4
- export type { RequestInitConfig, RefreshConfig, HttpRequestConfig, HttpResponse, HttpInstance, TokenResponse, } from '@clownlee/http';
4
+ export type { RequestInitConfig, RefreshConfig, HttpRequestConfig, HttpResponse, HttpStreamResponse, HttpInstance, TokenResponse, } from '@clownlee/http';
5
5
  export * from './apis';
6
6
  export * from './ui/permission-btn';
7
7
  export * from './ui/permission-table';
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,7 +2670,7 @@ 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;
2672
2675
  if (config._retry) {
2673
2676
  window.parent.postMessage({
@@ -2704,8 +2707,8 @@ async function handleResponseInterceptor(response, store, refreshConfig) {
2704
2707
  } catch (refreshError) {
2705
2708
  throw refreshError;
2706
2709
  }
2707
- } else if (code > 0) {
2708
- 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) ?? "请求失败");
2709
2712
  }
2710
2713
  return response;
2711
2714
  }
@@ -2786,11 +2789,8 @@ class RequestServiceClass {
2786
2789
  }
2787
2790
  return this.instance;
2788
2791
  }
2789
- /**
2790
- * 通用请求方法
2791
- */
2792
2792
  async request(config) {
2793
- var _a;
2793
+ var _a, _b;
2794
2794
  const instance = this.getInstance();
2795
2795
  const axiosConfig = {
2796
2796
  ...config,
@@ -2798,7 +2798,8 @@ class RequestServiceClass {
2798
2798
  cancelToken: config.cancelToken && "token" in config.cancelToken ? config.cancelToken.token : config.cancelToken
2799
2799
  };
2800
2800
  const response = await instance.request(axiosConfig);
2801
- if ((_a = response.headers["content-type"]) == null ? void 0 : _a.includes("application/octet-stream")) {
2801
+ const isBlobResponse = config.responseType === "blob" || ((_a = config.headers) == null ? void 0 : _a.responseType) === "blob" || ((_b = response.headers["content-type"]) == null ? void 0 : _b.includes("application/octet-stream"));
2802
+ if (isBlobResponse) {
2802
2803
  return response;
2803
2804
  }
2804
2805
  return response.data;
@@ -2875,7 +2876,7 @@ function init(config) {
2875
2876
  service.init(config);
2876
2877
  return service;
2877
2878
  }
2878
- let Apis$6 = class Apis {
2879
+ let Apis$5 = class Apis {
2879
2880
  constructor(config) {
2880
2881
  __publicField(this, "http");
2881
2882
  this.http = config || init(config);
@@ -2957,85 +2958,11 @@ let Apis$6 = class Apis {
2957
2958
  return await this.http.post("/api/v1/app/menu/update", data);
2958
2959
  }
2959
2960
  };
2960
- let Apis$5 = class Apis2 {
2961
+ class SubAppAuthApis {
2961
2962
  constructor(config) {
2962
2963
  __publicField(this, "http");
2963
2964
  this.http = config || init(config);
2964
2965
  }
2965
- /**
2966
- * 用户登录 API
2967
- * @param data 登录表单数据
2968
- * @returns 用户信息和Token
2969
- */
2970
- async login(data) {
2971
- return await this.http.post("/api/v1/iam/auth/login", data);
2972
- }
2973
- /**
2974
- * 用户登出 API
2975
- * @param data 登出数据,包含 userId、password、tenantId
2976
- * @returns 登出结果
2977
- */
2978
- async logout(data) {
2979
- return await this.http.post("/api/v1/iam/auth/logout", data || {});
2980
- }
2981
- /**
2982
- * 用户注册 API
2983
- * @param data 注册表单数据
2984
- * @returns 用户信息和Token
2985
- */
2986
- async register(data) {
2987
- return await this.http.post("/api/v1/iam/auth/register", data);
2988
- }
2989
- /**
2990
- * 获取租户列表 API
2991
- * @param type 租户类型:LOGIN(登录)或 REGISTER(注册)
2992
- * @returns 租户列表
2993
- */
2994
- async getTenants(type = "LOGIN") {
2995
- return await this.http.post("/api/v1/iam/auth/register/tenants", {
2996
- type
2997
- });
2998
- }
2999
- /**
3000
- * 获取授权码 API
3001
- * @param token 一次性Token(JWT)
3002
- * @returns 授权码
3003
- */
3004
- async getAuthorizationCode(token) {
3005
- return await this.http.get("/api/v1/iam/oauth2/authorize", null, {
3006
- headers: {
3007
- Authorization: `Bearer ${token}`
3008
- }
3009
- });
3010
- }
3011
- /**
3012
- * 获取AccessToken和RefreshToken API
3013
- * @param code 授权码
3014
- * @param token 一次性Token(JWT)
3015
- * @returns AccessToken和RefreshToken
3016
- */
3017
- async getAccessToken(code, token) {
3018
- return await this.http.post("/api/v1/iam/oauth2/token", {
3019
- grantType: "login_code",
3020
- code
3021
- }, {
3022
- headers: {
3023
- Authorization: `Bearer ${token}`
3024
- }
3025
- });
3026
- }
3027
- /**
3028
- * Token 刷新 API
3029
- * @param refreshToken RefreshToken
3030
- * @returns 新的AccessToken
3031
- */
3032
- async refreshToken(refreshToken) {
3033
- return await this.http.post("/api/v1/iam/auth/refresh-token", null, {
3034
- headers: {
3035
- Authorization: `Bearer ${refreshToken}`
3036
- }
3037
- });
3038
- }
3039
2966
  /**
3040
2967
  * 获取子应用授权码 API
3041
2968
  * @param clientId 客户端ID
@@ -3063,8 +2990,8 @@ let Apis$5 = class Apis2 {
3063
2990
  redirectUri
3064
2991
  });
3065
2992
  }
3066
- };
3067
- let Apis$4 = class Apis3 {
2993
+ }
2994
+ let Apis$4 = class Apis2 {
3068
2995
  constructor(config) {
3069
2996
  __publicField(this, "http");
3070
2997
  this.http = config || init(config);
@@ -3134,7 +3061,7 @@ let Apis$4 = class Apis3 {
3134
3061
  return await this.http.post("/api/v1/app/user/assignRoles", data);
3135
3062
  }
3136
3063
  };
3137
- let Apis$3 = class Apis4 {
3064
+ let Apis$3 = class Apis3 {
3138
3065
  constructor(config) {
3139
3066
  __publicField(this, "http");
3140
3067
  this.http = config || init(config);
@@ -3220,7 +3147,7 @@ let Apis$3 = class Apis4 {
3220
3147
  });
3221
3148
  }
3222
3149
  };
3223
- let Apis$2 = class Apis5 {
3150
+ let Apis$2 = class Apis4 {
3224
3151
  constructor(config) {
3225
3152
  __publicField(this, "http");
3226
3153
  this.http = config || init(config);
@@ -3290,7 +3217,7 @@ let Apis$2 = class Apis5 {
3290
3217
  });
3291
3218
  }
3292
3219
  };
3293
- let Apis$1 = class Apis6 {
3220
+ let Apis$1 = class Apis5 {
3294
3221
  constructor(config) {
3295
3222
  __publicField(this, "http");
3296
3223
  this.http = config || init(config);
@@ -3321,7 +3248,7 @@ let Apis$1 = class Apis6 {
3321
3248
  return await this.http.post("/api/v1/app/permission/getPermission");
3322
3249
  }
3323
3250
  };
3324
- class Apis7 {
3251
+ class Apis6 {
3325
3252
  constructor(config) {
3326
3253
  __publicField(this, "http");
3327
3254
  this.http = config || init(config);
@@ -22079,12 +22006,11 @@ function formatDateTime(dateTime) {
22079
22006
  const initHttp = init;
22080
22007
  export {
22081
22008
  Apis$4 as AppUserApis,
22082
- Apis$5 as AuthApis,
22083
22009
  _sfc_main$5 as Breadcrumb,
22084
22010
  Apis$3 as ClientApis,
22085
22011
  index as CropImage,
22086
22012
  iconsSelect as IconsSelect,
22087
- Apis$6 as MenuApis,
22013
+ Apis$5 as MenuApis,
22088
22014
  PERMISSION_CHECKER_KEY,
22089
22015
  PERMISSION_STORE_KEY,
22090
22016
  _sfc_main$1 as PageContainer,
@@ -22095,7 +22021,8 @@ export {
22095
22021
  Apis$2 as RoleApis,
22096
22022
  Apis$1 as RolePermissionApis,
22097
22023
  selectLoadMore as SelectLoadMore,
22098
- Apis7 as UserCenterApis,
22024
+ SubAppAuthApis,
22025
+ Apis6 as UserCenterApis,
22099
22026
  checkMultiplePermissionsAND,
22100
22027
  checkMultiplePermissionsOR,
22101
22028
  checkPermission,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clownlee/cores",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
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.5",
33
+ "@clownlee/http": "^1.0.8",
34
34
  "pinia": "^2.1.7",
35
35
  "vue": "^3.5.25",
36
36
  "cropper": "^4.1.0",