@etsoo/materialui 1.2.98 → 1.2.99

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.
@@ -27,7 +27,7 @@ export declare abstract class CommonApp<U extends IUser = IUser, P extends IPage
27
27
  * Refresh token
28
28
  * @param props Props
29
29
  */
30
- refreshToken<D extends object = RefreshTokenRQ>(props?: RefreshTokenProps<D>): Promise<boolean>;
30
+ refreshToken<D extends object = Partial<RefreshTokenRQ>>(props?: RefreshTokenProps<D>): Promise<boolean>;
31
31
  /**
32
32
  * Try login
33
33
  * @param data Additional data
@@ -0,0 +1,32 @@
1
+ import { IApi } from "@etsoo/restclient";
2
+ import { ISmartERPUser } from "./ISmartERPUser";
3
+ import { RefreshTokenRQ } from "@etsoo/appscript";
4
+ /**
5
+ * Service application API, Implement interface calls between different services
6
+ * 服务程序接口,实现不同服务之间的接口调用
7
+ */
8
+ export interface IAppApi {
9
+ /**
10
+ * API
11
+ */
12
+ readonly api: IApi<any>;
13
+ /**
14
+ * Service id
15
+ */
16
+ readonly serviceId: number;
17
+ /**
18
+ * Is once authorized
19
+ */
20
+ get onceAuthorized(): boolean;
21
+ /**
22
+ * Authorize the API
23
+ * @param user SmartERP user
24
+ * @param refreshToken SmartERP user refresh token
25
+ * @param token Access token
26
+ */
27
+ authorize(user: ISmartERPUser, refreshToken: string, token: string): void;
28
+ /**
29
+ * Get refresh token data
30
+ */
31
+ getrefreshTokenData(): Partial<RefreshTokenRQ>;
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -5,6 +5,13 @@ import { IServicePageData } from "./IServicePage";
5
5
  import { IServiceUser } from "./IServiceUser";
6
6
  import { ISmartERPUser } from "./ISmartERPUser";
7
7
  import { ReactApp } from "./ReactApp";
8
+ import { IAppApi } from "./IAppApi";
9
+ /**
10
+ * Service application refresh token properties
11
+ */
12
+ export interface ServiceRefreshTokenProps extends RefreshTokenProps<Partial<RefreshTokenRQ>> {
13
+ appApi?: IAppApi;
14
+ }
8
15
  /**
9
16
  * Core Service App
10
17
  * Service login to core system, get the refesh token and access token
@@ -46,7 +53,7 @@ export declare class ServiceApp<U extends IServiceUser = IServiceUser, P extends
46
53
  * Refresh token
47
54
  * @param props Props
48
55
  */
49
- refreshToken<D extends object = RefreshTokenRQ>(props?: RefreshTokenProps<D>): Promise<boolean>;
56
+ refreshToken(props?: ServiceRefreshTokenProps): Promise<boolean>;
50
57
  /**
51
58
  * Service decrypt message
52
59
  * @param messageEncrypted Encrypted message
@@ -138,10 +138,13 @@ export class ServiceApp extends ReactApp {
138
138
  }
139
139
  // Login
140
140
  if (appApi) {
141
+ if (!appApi.onceAuthorized) {
142
+ // API handling
143
+ this.setApiLoading(appApi.api);
144
+ this.setApiErrorHandler(appApi.api, true);
145
+ }
141
146
  // Authorize external service application API
142
- appApi.authorize(serviceResult.data.token);
143
- // Update core system token, otherwise will be failed for upcoming calls
144
- this.userLogin(userData, refreshToken, true);
147
+ appApi.authorize(userData, refreshToken, serviceResult.data.token);
145
148
  }
146
149
  else {
147
150
  // Authorize local service
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.2.98",
3
+ "version": "1.2.99",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "@emotion/css": "^11.11.2",
51
51
  "@emotion/react": "^11.11.1",
52
52
  "@emotion/styled": "^11.11.0",
53
- "@etsoo/appscript": "^1.4.35",
53
+ "@etsoo/appscript": "^1.4.37",
54
54
  "@etsoo/notificationbase": "^1.1.28",
55
55
  "@etsoo/react": "^1.7.7",
56
56
  "@etsoo/shared": "^1.2.10",
@@ -56,7 +56,7 @@ export abstract class CommonApp<
56
56
  * Refresh token
57
57
  * @param props Props
58
58
  */
59
- override async refreshToken<D extends object = RefreshTokenRQ>(
59
+ override async refreshToken<D extends object = Partial<RefreshTokenRQ>>(
60
60
  props?: RefreshTokenProps<D>
61
61
  ) {
62
62
  // Destruct
@@ -0,0 +1,37 @@
1
+ import { IApi } from "@etsoo/restclient";
2
+ import { ISmartERPUser } from "./ISmartERPUser";
3
+ import { RefreshTokenRQ } from "@etsoo/appscript";
4
+
5
+ /**
6
+ * Service application API, Implement interface calls between different services
7
+ * 服务程序接口,实现不同服务之间的接口调用
8
+ */
9
+ export interface IAppApi {
10
+ /**
11
+ * API
12
+ */
13
+ readonly api: IApi<any>;
14
+
15
+ /**
16
+ * Service id
17
+ */
18
+ readonly serviceId: number;
19
+
20
+ /**
21
+ * Is once authorized
22
+ */
23
+ get onceAuthorized(): boolean;
24
+
25
+ /**
26
+ * Authorize the API
27
+ * @param user SmartERP user
28
+ * @param refreshToken SmartERP user refresh token
29
+ * @param token Access token
30
+ */
31
+ authorize(user: ISmartERPUser, refreshToken: string, token: string): void;
32
+
33
+ /**
34
+ * Get refresh token data
35
+ */
36
+ getrefreshTokenData(): Partial<RefreshTokenRQ>;
37
+ }
@@ -16,6 +16,15 @@ import { IServicePageData } from "./IServicePage";
16
16
  import { IServiceUser, ServiceLoginResult } from "./IServiceUser";
17
17
  import { ISmartERPUser } from "./ISmartERPUser";
18
18
  import { ReactApp } from "./ReactApp";
19
+ import { IAppApi } from "./IAppApi";
20
+
21
+ /**
22
+ * Service application refresh token properties
23
+ */
24
+ export interface ServiceRefreshTokenProps
25
+ extends RefreshTokenProps<Partial<RefreshTokenRQ>> {
26
+ appApi?: IAppApi;
27
+ }
19
28
 
20
29
  /**
21
30
  * Core Service App
@@ -112,9 +121,7 @@ export class ServiceApp<
112
121
  * Refresh token
113
122
  * @param props Props
114
123
  */
115
- override async refreshToken<D extends object = RefreshTokenRQ>(
116
- props?: RefreshTokenProps<D>
117
- ) {
124
+ override async refreshToken(props?: ServiceRefreshTokenProps) {
118
125
  // Destruct
119
126
  const {
120
127
  appApi,
@@ -204,11 +211,14 @@ export class ServiceApp<
204
211
 
205
212
  // Login
206
213
  if (appApi) {
207
- // Authorize external service application API
208
- appApi.authorize(serviceResult.data.token);
214
+ if (!appApi.onceAuthorized) {
215
+ // API handling
216
+ this.setApiLoading(appApi.api);
217
+ this.setApiErrorHandler(appApi.api, true);
218
+ }
209
219
 
210
- // Update core system token, otherwise will be failed for upcoming calls
211
- this.userLogin(userData, refreshToken, true);
220
+ // Authorize external service application API
221
+ appApi.authorize(userData, refreshToken, serviceResult.data.token);
212
222
  } else {
213
223
  // Authorize local service
214
224
  this.userLoginEx(userData, refreshToken, serviceResult.data);