@etsoo/react 1.3.69 → 1.3.71

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,4 +1,4 @@
1
- import { IApi, InitCallDto, InitCallResult, RefreshTokenProps } from '@etsoo/appscript';
1
+ import { IApi, RefreshTokenProps } from '@etsoo/appscript';
2
2
  import { IServiceAppSettings } from './IServiceAppSettings';
3
3
  import { IServicePageData } from './IServicePage';
4
4
  import { IServiceUser } from './IServiceUser';
@@ -13,9 +13,9 @@ import { RefreshTokenRQ } from './RefreshTokenRQ';
13
13
  */
14
14
  export declare class ServiceApp<P extends IServicePageData = IServicePageData, U extends IServiceUser = IServiceUser, S extends IServiceAppSettings = IServiceAppSettings> extends ReactApp<S, U, P> {
15
15
  /**
16
- * Core system API
16
+ * Service API
17
17
  */
18
- readonly coreApi: IApi;
18
+ readonly serviceApi: IApi;
19
19
  /**
20
20
  * Core system user
21
21
  */
@@ -30,12 +30,6 @@ export declare class ServiceApp<P extends IServicePageData = IServicePageData, U
30
30
  * @param name Application name
31
31
  */
32
32
  constructor(settings: S, name: string);
33
- /**
34
- * Api init call, connect to the core Api
35
- * @param data Data
36
- * @returns Result
37
- */
38
- protected apiInitCall(data: InitCallDto): Promise<InitCallResult | undefined>;
39
33
  /**
40
34
  * Go to the login page
41
35
  */
@@ -21,28 +21,20 @@ export class ServiceApp extends ReactApp {
21
21
  */
22
22
  this.servicePassphrase = '';
23
23
  // Check
24
- if (settings.serviceId == null || settings.coreApi == null) {
24
+ if (settings.serviceId == null || settings.serviceEndpoint == null) {
25
25
  throw new Error('No service settings');
26
26
  }
27
- // Core API
27
+ // Service API
28
28
  const api = createClient();
29
- api.baseUrl = settings.coreApi;
29
+ api.baseUrl = settings.serviceEndpoint;
30
30
  this.setApi(api);
31
- this.coreApi = api;
32
- }
33
- /**
34
- * Api init call, connect to the core Api
35
- * @param data Data
36
- * @returns Result
37
- */
38
- async apiInitCall(data) {
39
- return await this.coreApi.put(this.initCallApi, data);
31
+ this.serviceApi = api;
40
32
  }
41
33
  /**
42
34
  * Go to the login page
43
35
  */
44
36
  toLoginPage() {
45
- const coreUrl = this.settings.coreUrl;
37
+ const coreUrl = this.settings.webUrl;
46
38
  window.location.href =
47
39
  coreUrl +
48
40
  '?serviceId=' +
@@ -96,7 +88,7 @@ export class ServiceApp extends ReactApp {
96
88
  // User data
97
89
  const userData = result.data;
98
90
  // Use core system access token to service api to exchange service access token
99
- const serviceResult = await this.api.put('Auth/ExchangeToken', {
91
+ const serviceResult = await this.serviceApi.put('Auth/ExchangeToken', {
100
92
  token: this.encryptEnhanced(userData.token, this.settings.serviceId.toString())
101
93
  }, {
102
94
  showLoading,
@@ -127,7 +119,7 @@ export class ServiceApp extends ReactApp {
127
119
  return true;
128
120
  };
129
121
  // Call API
130
- const result = await this.coreApi.put('Auth/RefreshToken', rq, payload);
122
+ const result = await this.api.put('Auth/RefreshToken', rq, payload);
131
123
  if (result == null)
132
124
  return false;
133
125
  if (!result.ok) {
@@ -143,7 +135,7 @@ export class ServiceApp extends ReactApp {
143
135
  // Set password for the action
144
136
  rq.pwd = this.encrypt(this.hash(pwd));
145
137
  // Submit again
146
- const result = await this.coreApi.put('Auth/RefreshToken', rq, payload);
138
+ const result = await this.api.put('Auth/RefreshToken', rq, payload);
147
139
  if (result == null)
148
140
  return;
149
141
  if (result.ok) {
@@ -233,10 +225,11 @@ export class ServiceApp extends ReactApp {
233
225
  // Service user login
234
226
  this.servicePassphrase =
235
227
  (_a = this.decrypt(user.serviceDeviceId, this.settings.serviceId.toString())) !== null && _a !== void 0 ? _a : '';
236
- super.userLogin(user, refreshToken, false);
228
+ // Keep = true, means service could hold the refresh token for long access
229
+ super.userLogin(user, refreshToken, true);
237
230
  // Core system user
238
231
  this.coreUser = coreUser;
239
- // Core system API token
240
- this.coreApi.authorize(this.settings.authScheme, coreUser.token);
232
+ // Service API token
233
+ this.serviceApi.authorize(this.settings.authScheme, coreUser.token);
241
234
  }
242
235
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.3.69",
3
+ "version": "1.3.71",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "@emotion/react": "^11.7.1",
51
51
  "@emotion/style": "^0.8.0",
52
52
  "@emotion/styled": "^11.6.0",
53
- "@etsoo/appscript": "^1.1.83",
53
+ "@etsoo/appscript": "^1.1.85",
54
54
  "@etsoo/notificationbase": "^1.0.94",
55
55
  "@etsoo/shared": "^1.0.78",
56
56
  "@mui/icons-material": "^5.2.4",
@@ -2,8 +2,6 @@ import {
2
2
  createClient,
3
3
  IApi,
4
4
  IApiPayload,
5
- InitCallDto,
6
- InitCallResult,
7
5
  RefreshTokenProps,
8
6
  RefreshTokenResult
9
7
  } from '@etsoo/appscript';
@@ -28,9 +26,9 @@ export class ServiceApp<
28
26
  S extends IServiceAppSettings = IServiceAppSettings
29
27
  > extends ReactApp<S, U, P> {
30
28
  /**
31
- * Core system API
29
+ * Service API
32
30
  */
33
- readonly coreApi: IApi;
31
+ readonly serviceApi: IApi;
34
32
 
35
33
  /**
36
34
  * Core system user
@@ -51,32 +49,23 @@ export class ServiceApp<
51
49
  super(settings, name);
52
50
 
53
51
  // Check
54
- if (settings.serviceId == null || settings.coreApi == null) {
52
+ if (settings.serviceId == null || settings.serviceEndpoint == null) {
55
53
  throw new Error('No service settings');
56
54
  }
57
55
 
58
- // Core API
56
+ // Service API
59
57
  const api = createClient();
60
- api.baseUrl = settings.coreApi;
58
+ api.baseUrl = settings.serviceEndpoint;
61
59
 
62
60
  this.setApi(api);
63
- this.coreApi = api;
64
- }
65
-
66
- /**
67
- * Api init call, connect to the core Api
68
- * @param data Data
69
- * @returns Result
70
- */
71
- protected override async apiInitCall(data: InitCallDto) {
72
- return await this.coreApi.put<InitCallResult>(this.initCallApi, data);
61
+ this.serviceApi = api;
73
62
  }
74
63
 
75
64
  /**
76
65
  * Go to the login page
77
66
  */
78
67
  override toLoginPage() {
79
- const coreUrl = this.settings.coreUrl;
68
+ const coreUrl = this.settings.webUrl;
80
69
  window.location.href =
81
70
  coreUrl +
82
71
  '?serviceId=' +
@@ -145,7 +134,7 @@ export class ServiceApp<
145
134
  const userData = result.data;
146
135
 
147
136
  // Use core system access token to service api to exchange service access token
148
- const serviceResult = await this.api.put<ServiceLoginResult>(
137
+ const serviceResult = await this.serviceApi.put<ServiceLoginResult>(
149
138
  'Auth/ExchangeToken',
150
139
  {
151
140
  token: this.encryptEnhanced(
@@ -186,7 +175,7 @@ export class ServiceApp<
186
175
  };
187
176
 
188
177
  // Call API
189
- const result = await this.coreApi.put<SmartERPLoginResult>(
178
+ const result = await this.api.put<SmartERPLoginResult>(
190
179
  'Auth/RefreshToken',
191
180
  rq,
192
181
  payload
@@ -210,12 +199,11 @@ export class ServiceApp<
210
199
  rq.pwd = this.encrypt(this.hash(pwd));
211
200
 
212
201
  // Submit again
213
- const result =
214
- await this.coreApi.put<SmartERPLoginResult>(
215
- 'Auth/RefreshToken',
216
- rq,
217
- payload
218
- );
202
+ const result = await this.api.put<SmartERPLoginResult>(
203
+ 'Auth/RefreshToken',
204
+ rq,
205
+ payload
206
+ );
219
207
 
220
208
  if (result == null) return;
221
209
 
@@ -336,12 +324,14 @@ export class ServiceApp<
336
324
  user.serviceDeviceId,
337
325
  this.settings.serviceId.toString()
338
326
  ) ?? '';
339
- super.userLogin(user, refreshToken, false);
327
+
328
+ // Keep = true, means service could hold the refresh token for long access
329
+ super.userLogin(user, refreshToken, true);
340
330
 
341
331
  // Core system user
342
332
  this.coreUser = coreUser;
343
333
 
344
- // Core system API token
345
- this.coreApi.authorize(this.settings.authScheme, coreUser.token);
334
+ // Service API token
335
+ this.serviceApi.authorize(this.settings.authScheme, coreUser.token);
346
336
  }
347
337
  }