@etsoo/react 1.3.69 → 1.3.74
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.
- package/lib/app/RefreshTokenRQ.d.ts +4 -0
- package/lib/app/ServiceApp.d.ts +11 -15
- package/lib/app/ServiceApp.js +27 -23
- package/package.json +8 -8
- package/src/app/RefreshTokenRQ.ts +5 -0
- package/src/app/ServiceApp.ts +38 -40
package/lib/app/ServiceApp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IApi,
|
|
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,29 +13,25 @@ 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
|
-
*
|
|
16
|
+
* Service API
|
|
17
17
|
*/
|
|
18
|
-
readonly
|
|
18
|
+
readonly serviceApi: IApi;
|
|
19
|
+
private _serviceUser?;
|
|
19
20
|
/**
|
|
20
|
-
*
|
|
21
|
+
* Service user
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
+
get serviceUser(): IServiceUser | undefined;
|
|
24
|
+
protected set serviceUser(value: IServiceUser | undefined);
|
|
23
25
|
/**
|
|
24
26
|
* Service passphrase
|
|
25
27
|
*/
|
|
26
|
-
servicePassphrase: string;
|
|
28
|
+
protected servicePassphrase: string;
|
|
27
29
|
/**
|
|
28
30
|
* Constructor
|
|
29
31
|
* @param settings Settings
|
|
30
32
|
* @param name Application name
|
|
31
33
|
*/
|
|
32
34
|
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
35
|
/**
|
|
40
36
|
* Go to the login page
|
|
41
37
|
*/
|
|
@@ -67,9 +63,9 @@ export declare class ServiceApp<P extends IServicePageData = IServicePageData, U
|
|
|
67
63
|
tryLogin<D extends {} = {}>(data?: D): Promise<boolean>;
|
|
68
64
|
/**
|
|
69
65
|
* User login extended
|
|
70
|
-
* @param user
|
|
66
|
+
* @param user Core system user
|
|
71
67
|
* @param refreshToken Refresh token
|
|
72
|
-
* @param
|
|
68
|
+
* @param serviceUser Service user
|
|
73
69
|
*/
|
|
74
|
-
userLoginEx(user:
|
|
70
|
+
userLoginEx(user: ISmartERPUser, refreshToken: string, serviceUser: IServiceUser): void;
|
|
75
71
|
}
|
package/lib/app/ServiceApp.js
CHANGED
|
@@ -21,32 +21,35 @@ export class ServiceApp extends ReactApp {
|
|
|
21
21
|
*/
|
|
22
22
|
this.servicePassphrase = '';
|
|
23
23
|
// Check
|
|
24
|
-
if (settings.serviceId == null || settings.
|
|
24
|
+
if (settings.serviceId == null || settings.serviceEndpoint == null) {
|
|
25
25
|
throw new Error('No service settings');
|
|
26
26
|
}
|
|
27
|
-
//
|
|
27
|
+
// Service API
|
|
28
28
|
const api = createClient();
|
|
29
|
-
api.baseUrl = settings.
|
|
29
|
+
api.baseUrl = settings.serviceEndpoint;
|
|
30
30
|
this.setApi(api);
|
|
31
|
-
this.
|
|
31
|
+
this.serviceApi = api;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param data Data
|
|
36
|
-
* @returns Result
|
|
34
|
+
* Service user
|
|
37
35
|
*/
|
|
38
|
-
|
|
39
|
-
return
|
|
36
|
+
get serviceUser() {
|
|
37
|
+
return this._serviceUser;
|
|
38
|
+
}
|
|
39
|
+
set serviceUser(value) {
|
|
40
|
+
this._serviceUser = value;
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
42
43
|
* Go to the login page
|
|
43
44
|
*/
|
|
44
45
|
toLoginPage() {
|
|
45
|
-
const coreUrl = this.settings.
|
|
46
|
+
const coreUrl = this.settings.webUrl;
|
|
46
47
|
window.location.href =
|
|
47
48
|
coreUrl +
|
|
48
49
|
'?serviceId=' +
|
|
49
50
|
this.settings.serviceId +
|
|
51
|
+
'&serviceDeviceId=' +
|
|
52
|
+
this.deviceId +
|
|
50
53
|
'&' +
|
|
51
54
|
DomUtils.Culture +
|
|
52
55
|
'=' +
|
|
@@ -96,7 +99,7 @@ export class ServiceApp extends ReactApp {
|
|
|
96
99
|
// User data
|
|
97
100
|
const userData = result.data;
|
|
98
101
|
// Use core system access token to service api to exchange service access token
|
|
99
|
-
const serviceResult = await this.
|
|
102
|
+
const serviceResult = await this.serviceApi.put('Auth/ExchangeToken', {
|
|
100
103
|
token: this.encryptEnhanced(userData.token, this.settings.serviceId.toString())
|
|
101
104
|
}, {
|
|
102
105
|
showLoading,
|
|
@@ -120,14 +123,14 @@ export class ServiceApp extends ReactApp {
|
|
|
120
123
|
return false;
|
|
121
124
|
}
|
|
122
125
|
// Login
|
|
123
|
-
this.userLoginEx(
|
|
126
|
+
this.userLoginEx(userData, refreshToken, serviceResult.data);
|
|
124
127
|
// Success callback
|
|
125
128
|
if (failCallback)
|
|
126
129
|
failCallback(true);
|
|
127
130
|
return true;
|
|
128
131
|
};
|
|
129
132
|
// Call API
|
|
130
|
-
const result = await this.
|
|
133
|
+
const result = await this.api.put('Auth/RefreshToken', rq, payload);
|
|
131
134
|
if (result == null)
|
|
132
135
|
return false;
|
|
133
136
|
if (!result.ok) {
|
|
@@ -143,7 +146,7 @@ export class ServiceApp extends ReactApp {
|
|
|
143
146
|
// Set password for the action
|
|
144
147
|
rq.pwd = this.encrypt(this.hash(pwd));
|
|
145
148
|
// Submit again
|
|
146
|
-
const result = await this.
|
|
149
|
+
const result = await this.api.put('Auth/RefreshToken', rq, payload);
|
|
147
150
|
if (result == null)
|
|
148
151
|
return;
|
|
149
152
|
if (result.ok) {
|
|
@@ -224,19 +227,20 @@ export class ServiceApp extends ReactApp {
|
|
|
224
227
|
}
|
|
225
228
|
/**
|
|
226
229
|
* User login extended
|
|
227
|
-
* @param user
|
|
230
|
+
* @param user Core system user
|
|
228
231
|
* @param refreshToken Refresh token
|
|
229
|
-
* @param
|
|
232
|
+
* @param serviceUser Service user
|
|
230
233
|
*/
|
|
231
|
-
userLoginEx(user, refreshToken,
|
|
234
|
+
userLoginEx(user, refreshToken, serviceUser) {
|
|
232
235
|
var _a;
|
|
233
236
|
// Service user login
|
|
234
237
|
this.servicePassphrase =
|
|
235
|
-
(_a = this.decrypt(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
238
|
+
(_a = this.decrypt(serviceUser.serviceDeviceId, this.settings.serviceId.toString())) !== null && _a !== void 0 ? _a : '';
|
|
239
|
+
// Keep = true, means service could hold the refresh token for long access
|
|
240
|
+
super.userLogin(user, refreshToken, true);
|
|
241
|
+
// Service user
|
|
242
|
+
this.serviceUser = serviceUser;
|
|
243
|
+
// Service API token
|
|
244
|
+
this.serviceApi.authorize(this.settings.authScheme, serviceUser.token);
|
|
241
245
|
}
|
|
242
246
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.74",
|
|
4
4
|
"description": "TypeScript ReactJs framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -50,11 +50,11 @@
|
|
|
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.
|
|
54
|
-
"@etsoo/notificationbase": "^1.0.
|
|
55
|
-
"@etsoo/shared": "^1.0.
|
|
56
|
-
"@mui/icons-material": "^5.2.
|
|
57
|
-
"@mui/material": "^5.2.
|
|
53
|
+
"@etsoo/appscript": "^1.1.89",
|
|
54
|
+
"@etsoo/notificationbase": "^1.0.95",
|
|
55
|
+
"@etsoo/shared": "^1.0.82",
|
|
56
|
+
"@mui/icons-material": "^5.2.5",
|
|
57
|
+
"@mui/material": "^5.2.5",
|
|
58
58
|
"@reach/router": "^1.3.4",
|
|
59
59
|
"@types/pica": "^5.1.3",
|
|
60
60
|
"@types/pulltorefreshjs": "^0.1.5",
|
|
@@ -81,8 +81,8 @@
|
|
|
81
81
|
"@babel/runtime-corejs3": "^7.16.5",
|
|
82
82
|
"@types/jest": "^27.0.3",
|
|
83
83
|
"@types/react-test-renderer": "^17.0.1",
|
|
84
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
85
|
-
"@typescript-eslint/parser": "^5.
|
|
84
|
+
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
|
85
|
+
"@typescript-eslint/parser": "^5.8.0",
|
|
86
86
|
"eslint": "^8.5.0",
|
|
87
87
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
88
88
|
"eslint-plugin-import": "^2.25.3",
|
package/src/app/ServiceApp.ts
CHANGED
|
@@ -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,19 +26,25 @@ export class ServiceApp<
|
|
|
28
26
|
S extends IServiceAppSettings = IServiceAppSettings
|
|
29
27
|
> extends ReactApp<S, U, P> {
|
|
30
28
|
/**
|
|
31
|
-
*
|
|
29
|
+
* Service API
|
|
32
30
|
*/
|
|
33
|
-
readonly
|
|
31
|
+
readonly serviceApi: IApi;
|
|
34
32
|
|
|
33
|
+
private _serviceUser?: IServiceUser;
|
|
35
34
|
/**
|
|
36
|
-
*
|
|
35
|
+
* Service user
|
|
37
36
|
*/
|
|
38
|
-
|
|
37
|
+
get serviceUser() {
|
|
38
|
+
return this._serviceUser;
|
|
39
|
+
}
|
|
40
|
+
protected set serviceUser(value: IServiceUser | undefined) {
|
|
41
|
+
this._serviceUser = value;
|
|
42
|
+
}
|
|
39
43
|
|
|
40
44
|
/**
|
|
41
45
|
* Service passphrase
|
|
42
46
|
*/
|
|
43
|
-
servicePassphrase: string = '';
|
|
47
|
+
protected servicePassphrase: string = '';
|
|
44
48
|
|
|
45
49
|
/**
|
|
46
50
|
* Constructor
|
|
@@ -51,36 +55,29 @@ export class ServiceApp<
|
|
|
51
55
|
super(settings, name);
|
|
52
56
|
|
|
53
57
|
// Check
|
|
54
|
-
if (settings.serviceId == null || settings.
|
|
58
|
+
if (settings.serviceId == null || settings.serviceEndpoint == null) {
|
|
55
59
|
throw new Error('No service settings');
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
//
|
|
62
|
+
// Service API
|
|
59
63
|
const api = createClient();
|
|
60
|
-
api.baseUrl = settings.
|
|
64
|
+
api.baseUrl = settings.serviceEndpoint;
|
|
61
65
|
|
|
62
66
|
this.setApi(api);
|
|
63
|
-
this.
|
|
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);
|
|
67
|
+
this.serviceApi = api;
|
|
73
68
|
}
|
|
74
69
|
|
|
75
70
|
/**
|
|
76
71
|
* Go to the login page
|
|
77
72
|
*/
|
|
78
73
|
override toLoginPage() {
|
|
79
|
-
const coreUrl = this.settings.
|
|
74
|
+
const coreUrl = this.settings.webUrl;
|
|
80
75
|
window.location.href =
|
|
81
76
|
coreUrl +
|
|
82
77
|
'?serviceId=' +
|
|
83
78
|
this.settings.serviceId +
|
|
79
|
+
'&serviceDeviceId=' +
|
|
80
|
+
this.deviceId +
|
|
84
81
|
'&' +
|
|
85
82
|
DomUtils.Culture +
|
|
86
83
|
'=' +
|
|
@@ -145,7 +142,7 @@ export class ServiceApp<
|
|
|
145
142
|
const userData = result.data;
|
|
146
143
|
|
|
147
144
|
// Use core system access token to service api to exchange service access token
|
|
148
|
-
const serviceResult = await this.
|
|
145
|
+
const serviceResult = await this.serviceApi.put<ServiceLoginResult>(
|
|
149
146
|
'Auth/ExchangeToken',
|
|
150
147
|
{
|
|
151
148
|
token: this.encryptEnhanced(
|
|
@@ -177,7 +174,7 @@ export class ServiceApp<
|
|
|
177
174
|
}
|
|
178
175
|
|
|
179
176
|
// Login
|
|
180
|
-
this.userLoginEx(
|
|
177
|
+
this.userLoginEx(userData, refreshToken, serviceResult.data);
|
|
181
178
|
|
|
182
179
|
// Success callback
|
|
183
180
|
if (failCallback) failCallback(true);
|
|
@@ -186,7 +183,7 @@ export class ServiceApp<
|
|
|
186
183
|
};
|
|
187
184
|
|
|
188
185
|
// Call API
|
|
189
|
-
const result = await this.
|
|
186
|
+
const result = await this.api.put<SmartERPLoginResult>(
|
|
190
187
|
'Auth/RefreshToken',
|
|
191
188
|
rq,
|
|
192
189
|
payload
|
|
@@ -210,12 +207,11 @@ export class ServiceApp<
|
|
|
210
207
|
rq.pwd = this.encrypt(this.hash(pwd));
|
|
211
208
|
|
|
212
209
|
// Submit again
|
|
213
|
-
const result =
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
);
|
|
210
|
+
const result = await this.api.put<SmartERPLoginResult>(
|
|
211
|
+
'Auth/RefreshToken',
|
|
212
|
+
rq,
|
|
213
|
+
payload
|
|
214
|
+
);
|
|
219
215
|
|
|
220
216
|
if (result == null) return;
|
|
221
217
|
|
|
@@ -321,27 +317,29 @@ export class ServiceApp<
|
|
|
321
317
|
|
|
322
318
|
/**
|
|
323
319
|
* User login extended
|
|
324
|
-
* @param user
|
|
320
|
+
* @param user Core system user
|
|
325
321
|
* @param refreshToken Refresh token
|
|
326
|
-
* @param
|
|
322
|
+
* @param serviceUser Service user
|
|
327
323
|
*/
|
|
328
324
|
userLoginEx(
|
|
329
|
-
user:
|
|
325
|
+
user: ISmartERPUser,
|
|
330
326
|
refreshToken: string,
|
|
331
|
-
|
|
327
|
+
serviceUser: IServiceUser
|
|
332
328
|
): void {
|
|
333
329
|
// Service user login
|
|
334
330
|
this.servicePassphrase =
|
|
335
331
|
this.decrypt(
|
|
336
|
-
|
|
332
|
+
serviceUser.serviceDeviceId,
|
|
337
333
|
this.settings.serviceId.toString()
|
|
338
334
|
) ?? '';
|
|
339
|
-
super.userLogin(user, refreshToken, false);
|
|
340
335
|
|
|
341
|
-
//
|
|
342
|
-
|
|
336
|
+
// Keep = true, means service could hold the refresh token for long access
|
|
337
|
+
super.userLogin(user, refreshToken, true);
|
|
338
|
+
|
|
339
|
+
// Service user
|
|
340
|
+
this.serviceUser = serviceUser;
|
|
343
341
|
|
|
344
|
-
//
|
|
345
|
-
this.
|
|
342
|
+
// Service API token
|
|
343
|
+
this.serviceApi.authorize(this.settings.authScheme, serviceUser.token);
|
|
346
344
|
}
|
|
347
345
|
}
|