@etsoo/materialui 1.3.93 → 1.3.95

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,6 @@
1
- import { IApi } from "@etsoo/appscript";
1
+ import { ApiRefreshTokenDto, IApi } from "@etsoo/appscript";
2
2
  import { ReactAppType } from "./ReactApp";
3
+ import { IServiceUser, ServiceUserToken } from "./IServiceUser";
3
4
  /**
4
5
  * Service application interface
5
6
  */
@@ -12,4 +13,12 @@ export interface IServiceApp extends ReactAppType {
12
13
  * Load core system UI
13
14
  */
14
15
  loadCore(): void;
16
+ /**
17
+ *
18
+ * @param user Current user
19
+ * @param core Core system API token data
20
+ * @param keep Keep in local storage or not
21
+ * @param dispatch User state dispatch
22
+ */
23
+ userLoginEx(user: IServiceUser & ServiceUserToken, core?: ApiRefreshTokenDto, keep?: boolean, dispatch?: boolean): void;
15
24
  }
@@ -20,11 +20,22 @@ export interface IServiceUser extends IUser {
20
20
  */
21
21
  readonly passphrase?: string;
22
22
  /**
23
- * Device id
24
- * 设备编号
23
+ * Client device id
24
+ * 客户端设备编号
25
25
  */
26
- readonly deviceId?: string;
26
+ readonly clientDeviceId?: string;
27
27
  }
28
+ /**
29
+ * Service user token return type
30
+ * 服务用户令牌返回类型
31
+ */
32
+ export type ServiceUserToken = {
33
+ /**
34
+ * Refresh token
35
+ * 刷新令牌
36
+ */
37
+ readonly refreshToken: string;
38
+ };
28
39
  /**
29
40
  * Service user login result
30
41
  */
@@ -1,8 +1,8 @@
1
- import { ExternalEndpoint, IApi } from "@etsoo/appscript";
1
+ import { ApiRefreshTokenDto, ExternalEndpoint, IApi } from "@etsoo/appscript";
2
2
  import { IServiceApp } from "./IServiceApp";
3
3
  import { IServiceAppSettings } from "./IServiceAppSettings";
4
4
  import { IServicePageData } from "./IServicePage";
5
- import { IServiceUser } from "./IServiceUser";
5
+ import { IServiceUser, ServiceUserToken } from "./IServiceUser";
6
6
  import { ReactApp } from "./ReactApp";
7
7
  /**
8
8
  * Core Service App
@@ -44,4 +44,12 @@ export declare class ServiceApp<U extends IServiceUser = IServiceUser, P extends
44
44
  * @param dispatch User state dispatch
45
45
  */
46
46
  userLogin(user: U, refreshToken: string, keep?: boolean, dispatch?: boolean): void;
47
+ /**
48
+ *
49
+ * @param user Current user
50
+ * @param core Core system API token data
51
+ * @param keep Keep in local storage or not
52
+ * @param dispatch User state dispatch
53
+ */
54
+ userLoginEx(user: U & ServiceUserToken, core?: ApiRefreshTokenDto, keep?: boolean, dispatch?: boolean): void;
47
55
  }
@@ -42,8 +42,6 @@ export class ServiceApp extends ReactApp {
42
42
  toLoginPage(tryLogin, removeUrl) {
43
43
  // Cache current URL
44
44
  this.cachedUrl = removeUrl ? undefined : globalThis.location.href;
45
- // Make sure apply new device id for new login
46
- this.clearDeviceId();
47
45
  // Get the redirect URL
48
46
  this.api
49
47
  .get("Auth/GetLogInUrl", {
@@ -53,7 +51,8 @@ export class ServiceApp extends ReactApp {
53
51
  .then((url) => {
54
52
  if (!url)
55
53
  return;
56
- url += `?tryLogin=${tryLogin ?? false}`;
54
+ // Add try login flag
55
+ url = url.addUrlParam("tryLogin", tryLogin ?? false);
57
56
  if (BridgeUtils.host == null) {
58
57
  globalThis.location.href = url;
59
58
  }
@@ -61,6 +60,8 @@ export class ServiceApp extends ReactApp {
61
60
  BridgeUtils.host.loadApp(coreName, url);
62
61
  }
63
62
  });
63
+ // Make sure apply new device id for new login
64
+ this.clearDeviceId();
64
65
  }
65
66
  /**
66
67
  * User login extended
@@ -72,13 +73,33 @@ export class ServiceApp extends ReactApp {
72
73
  userLogin(user, refreshToken, keep, dispatch) {
73
74
  // Super call, set token
74
75
  super.userLogin(user, refreshToken, keep, dispatch);
75
- if (user.deviceId && user.passphrase) {
76
+ if (user.clientDeviceId && user.passphrase) {
76
77
  // Save the passphrase
77
78
  const passphrase = this.decrypt(user.passphrase, `${user.uid}-${this.settings.appId}`);
78
79
  if (passphrase) {
79
- this.deviceId = user.deviceId;
80
+ this.deviceId = user.clientDeviceId;
80
81
  this.updatePassphrase(passphrase);
81
82
  }
82
83
  }
83
84
  }
85
+ /**
86
+ *
87
+ * @param user Current user
88
+ * @param core Core system API token data
89
+ * @param keep Keep in local storage or not
90
+ * @param dispatch User state dispatch
91
+ */
92
+ userLoginEx(user, core, keep, dispatch) {
93
+ // User login
94
+ const { refreshToken } = user;
95
+ this.userLogin(user, refreshToken, keep, dispatch);
96
+ // Core system login
97
+ core ?? (core = {
98
+ refreshToken,
99
+ accessToken: user.token,
100
+ tokenType: user.tokenScheme ?? "Bearer",
101
+ expiresIn: user.seconds
102
+ });
103
+ this.exchangeTokenAll(core, coreName);
104
+ }
84
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.3.93",
3
+ "version": "1.3.95",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,12 +50,12 @@
50
50
  "@emotion/css": "^11.13.4",
51
51
  "@emotion/react": "^11.13.3",
52
52
  "@emotion/styled": "^11.13.0",
53
- "@etsoo/appscript": "^1.5.26",
54
- "@etsoo/notificationbase": "^1.1.48",
55
- "@etsoo/react": "^1.7.68",
56
- "@etsoo/shared": "^1.2.46",
57
- "@mui/icons-material": "^6.1.2",
58
- "@mui/material": "^6.1.2",
53
+ "@etsoo/appscript": "^1.5.28",
54
+ "@etsoo/notificationbase": "^1.1.49",
55
+ "@etsoo/react": "^1.7.69",
56
+ "@etsoo/shared": "^1.2.48",
57
+ "@mui/icons-material": "^6.1.3",
58
+ "@mui/material": "^6.1.3",
59
59
  "@mui/x-data-grid": "^7.19.0",
60
60
  "chart.js": "^4.4.4",
61
61
  "chartjs-plugin-datalabels": "^2.2.0",
@@ -1,5 +1,6 @@
1
- import { IApi } from "@etsoo/appscript";
1
+ import { ApiRefreshTokenDto, IApi } from "@etsoo/appscript";
2
2
  import { ReactAppType } from "./ReactApp";
3
+ import { IServiceUser, ServiceUserToken } from "./IServiceUser";
3
4
 
4
5
  /**
5
6
  * Service application interface
@@ -14,4 +15,18 @@ export interface IServiceApp extends ReactAppType {
14
15
  * Load core system UI
15
16
  */
16
17
  loadCore(): void;
18
+
19
+ /**
20
+ *
21
+ * @param user Current user
22
+ * @param core Core system API token data
23
+ * @param keep Keep in local storage or not
24
+ * @param dispatch User state dispatch
25
+ */
26
+ userLoginEx(
27
+ user: IServiceUser & ServiceUserToken,
28
+ core?: ApiRefreshTokenDto,
29
+ keep?: boolean,
30
+ dispatch?: boolean
31
+ ): void;
17
32
  }
@@ -24,12 +24,24 @@ export interface IServiceUser extends IUser {
24
24
  readonly passphrase?: string;
25
25
 
26
26
  /**
27
- * Device id
28
- * 设备编号
27
+ * Client device id
28
+ * 客户端设备编号
29
29
  */
30
- readonly deviceId?: string;
30
+ readonly clientDeviceId?: string;
31
31
  }
32
32
 
33
+ /**
34
+ * Service user token return type
35
+ * 服务用户令牌返回类型
36
+ */
37
+ export type ServiceUserToken = {
38
+ /**
39
+ * Refresh token
40
+ * 刷新令牌
41
+ */
42
+ readonly refreshToken: string;
43
+ };
44
+
33
45
  /**
34
46
  * Service user login result
35
47
  */
@@ -1,8 +1,13 @@
1
- import { BridgeUtils, ExternalEndpoint, IApi } from "@etsoo/appscript";
1
+ import {
2
+ ApiRefreshTokenDto,
3
+ BridgeUtils,
4
+ ExternalEndpoint,
5
+ IApi
6
+ } from "@etsoo/appscript";
2
7
  import { IServiceApp } from "./IServiceApp";
3
8
  import { IServiceAppSettings } from "./IServiceAppSettings";
4
9
  import { IServicePageData } from "./IServicePage";
5
- import { IServiceUser } from "./IServiceUser";
10
+ import { IServiceUser, ServiceUserToken } from "./IServiceUser";
6
11
  import { ReactApp } from "./ReactApp";
7
12
 
8
13
  const coreName = "core";
@@ -69,9 +74,6 @@ export class ServiceApp<
69
74
  // Cache current URL
70
75
  this.cachedUrl = removeUrl ? undefined : globalThis.location.href;
71
76
 
72
- // Make sure apply new device id for new login
73
- this.clearDeviceId();
74
-
75
77
  // Get the redirect URL
76
78
  this.api
77
79
  .get<string>("Auth/GetLogInUrl", {
@@ -81,7 +83,8 @@ export class ServiceApp<
81
83
  .then((url) => {
82
84
  if (!url) return;
83
85
 
84
- url += `?tryLogin=${tryLogin ?? false}`;
86
+ // Add try login flag
87
+ url = url.addUrlParam("tryLogin", tryLogin ?? false);
85
88
 
86
89
  if (BridgeUtils.host == null) {
87
90
  globalThis.location.href = url;
@@ -89,6 +92,9 @@ export class ServiceApp<
89
92
  BridgeUtils.host.loadApp(coreName, url);
90
93
  }
91
94
  });
95
+
96
+ // Make sure apply new device id for new login
97
+ this.clearDeviceId();
92
98
  }
93
99
 
94
100
  /**
@@ -107,16 +113,44 @@ export class ServiceApp<
107
113
  // Super call, set token
108
114
  super.userLogin(user, refreshToken, keep, dispatch);
109
115
 
110
- if (user.deviceId && user.passphrase) {
116
+ if (user.clientDeviceId && user.passphrase) {
111
117
  // Save the passphrase
112
118
  const passphrase = this.decrypt(
113
119
  user.passphrase,
114
120
  `${user.uid}-${this.settings.appId}`
115
121
  );
116
122
  if (passphrase) {
117
- this.deviceId = user.deviceId;
123
+ this.deviceId = user.clientDeviceId;
118
124
  this.updatePassphrase(passphrase);
119
125
  }
120
126
  }
121
127
  }
128
+
129
+ /**
130
+ *
131
+ * @param user Current user
132
+ * @param core Core system API token data
133
+ * @param keep Keep in local storage or not
134
+ * @param dispatch User state dispatch
135
+ */
136
+ userLoginEx(
137
+ user: U & ServiceUserToken,
138
+ core?: ApiRefreshTokenDto,
139
+ keep?: boolean,
140
+ dispatch?: boolean
141
+ ) {
142
+ // User login
143
+ const { refreshToken } = user;
144
+ this.userLogin(user, refreshToken, keep, dispatch);
145
+
146
+ // Core system login
147
+ core ??= {
148
+ refreshToken,
149
+ accessToken: user.token,
150
+ tokenType: user.tokenScheme ?? "Bearer",
151
+ expiresIn: user.seconds
152
+ };
153
+
154
+ this.exchangeTokenAll(core, coreName);
155
+ }
122
156
  }