@etsoo/materialui 1.2.98 → 1.3.0

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 {};
@@ -1,6 +1,7 @@
1
- import { IApi } from "@etsoo/appscript";
1
+ import { IApi, RefreshTokenResult } from "@etsoo/appscript";
2
2
  import { IServiceUser } from "./IServiceUser";
3
3
  import { ReactAppType } from "./ReactApp";
4
+ import { IAppApi } from "./IAppApi";
4
5
  /**
5
6
  * Service application interface
6
7
  */
@@ -13,6 +14,12 @@ export interface IServiceApp extends ReactAppType {
13
14
  * Service user
14
15
  */
15
16
  readonly serviceUser?: IServiceUser;
17
+ /**
18
+ * Service application API login
19
+ * @param appApi Service application API
20
+ * @param callback Callback
21
+ */
22
+ apiLogin(appApi: IAppApi, callback?: (result: RefreshTokenResult, successData?: string) => void): Promise<boolean>;
16
23
  /**
17
24
  * Load SmartERP core
18
25
  */
@@ -1,10 +1,17 @@
1
- import { IApi, RefreshTokenProps, RefreshTokenRQ } from "@etsoo/appscript";
1
+ import { IApi, RefreshTokenProps, RefreshTokenResult, RefreshTokenRQ } from "@etsoo/appscript";
2
2
  import { IServiceApp } from "./IServiceApp";
3
3
  import { IServiceAppSettings } from "./IServiceAppSettings";
4
4
  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
@@ -32,6 +39,12 @@ export declare class ServiceApp<U extends IServiceUser = IServiceUser, P extends
32
39
  * @param name Application name
33
40
  */
34
41
  constructor(settings: S, name: string);
42
+ /**
43
+ * Service application API login
44
+ * @param appApi Service application API
45
+ * @param callback Callback
46
+ */
47
+ apiLogin(appApi: IAppApi, callback?: (result: RefreshTokenResult, successData?: string) => void): Promise<boolean>;
35
48
  /**
36
49
  * Load SmartERP core
37
50
  */
@@ -46,7 +59,7 @@ export declare class ServiceApp<U extends IServiceUser = IServiceUser, P extends
46
59
  * Refresh token
47
60
  * @param props Props
48
61
  */
49
- refreshToken<D extends object = RefreshTokenRQ>(props?: RefreshTokenProps<D>): Promise<boolean>;
62
+ refreshToken(props?: ServiceRefreshTokenProps): Promise<boolean>;
50
63
  /**
51
64
  * Service decrypt message
52
65
  * @param messageEncrypted Encrypted message
@@ -40,6 +40,20 @@ export class ServiceApp extends ReactApp {
40
40
  api.baseUrl = settings.serviceEndpoint;
41
41
  this.serviceApi = api;
42
42
  }
43
+ /**
44
+ * Service application API login
45
+ * @param appApi Service application API
46
+ * @param callback Callback
47
+ */
48
+ apiLogin(appApi, callback) {
49
+ return this.refreshToken({
50
+ callback,
51
+ data: appApi.getrefreshTokenData(),
52
+ relogin: false,
53
+ showLoading: false,
54
+ appApi
55
+ });
56
+ }
43
57
  /**
44
58
  * Load SmartERP core
45
59
  */
@@ -138,10 +152,13 @@ export class ServiceApp extends ReactApp {
138
152
  }
139
153
  // Login
140
154
  if (appApi) {
155
+ if (!appApi.onceAuthorized) {
156
+ // API handling
157
+ this.setApiLoading(appApi.api);
158
+ this.setApiErrorHandler(appApi.api, true);
159
+ }
141
160
  // 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);
161
+ appApi.authorize(userData, refreshToken, serviceResult.data.token);
145
162
  }
146
163
  else {
147
164
  // 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.3.0",
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
+ }
@@ -1,6 +1,7 @@
1
- import { IApi } from "@etsoo/appscript";
1
+ import { IApi, RefreshTokenResult } from "@etsoo/appscript";
2
2
  import { IServiceUser } from "./IServiceUser";
3
3
  import { ReactAppType } from "./ReactApp";
4
+ import { IAppApi } from "./IAppApi";
4
5
 
5
6
  /**
6
7
  * Service application interface
@@ -16,6 +17,16 @@ export interface IServiceApp extends ReactAppType {
16
17
  */
17
18
  readonly serviceUser?: IServiceUser;
18
19
 
20
+ /**
21
+ * Service application API login
22
+ * @param appApi Service application API
23
+ * @param callback Callback
24
+ */
25
+ apiLogin(
26
+ appApi: IAppApi,
27
+ callback?: (result: RefreshTokenResult, successData?: string) => void
28
+ ): Promise<boolean>;
29
+
19
30
  /**
20
31
  * Load SmartERP core
21
32
  */
@@ -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
@@ -75,6 +84,24 @@ export class ServiceApp<
75
84
  this.serviceApi = api;
76
85
  }
77
86
 
87
+ /**
88
+ * Service application API login
89
+ * @param appApi Service application API
90
+ * @param callback Callback
91
+ */
92
+ apiLogin(
93
+ appApi: IAppApi,
94
+ callback?: (result: RefreshTokenResult, successData?: string) => void
95
+ ) {
96
+ return this.refreshToken({
97
+ callback,
98
+ data: appApi.getrefreshTokenData(),
99
+ relogin: false,
100
+ showLoading: false,
101
+ appApi
102
+ });
103
+ }
104
+
78
105
  /**
79
106
  * Load SmartERP core
80
107
  */
@@ -112,9 +139,7 @@ export class ServiceApp<
112
139
  * Refresh token
113
140
  * @param props Props
114
141
  */
115
- override async refreshToken<D extends object = RefreshTokenRQ>(
116
- props?: RefreshTokenProps<D>
117
- ) {
142
+ override async refreshToken(props?: ServiceRefreshTokenProps) {
118
143
  // Destruct
119
144
  const {
120
145
  appApi,
@@ -204,11 +229,14 @@ export class ServiceApp<
204
229
 
205
230
  // Login
206
231
  if (appApi) {
207
- // Authorize external service application API
208
- appApi.authorize(serviceResult.data.token);
232
+ if (!appApi.onceAuthorized) {
233
+ // API handling
234
+ this.setApiLoading(appApi.api);
235
+ this.setApiErrorHandler(appApi.api, true);
236
+ }
209
237
 
210
- // Update core system token, otherwise will be failed for upcoming calls
211
- this.userLogin(userData, refreshToken, true);
238
+ // Authorize external service application API
239
+ appApi.authorize(userData, refreshToken, serviceResult.data.token);
212
240
  } else {
213
241
  // Authorize local service
214
242
  this.userLoginEx(userData, refreshToken, serviceResult.data);