@etsoo/react 1.3.66 → 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.
- package/lib/app/IServiceUser.d.ts +4 -0
- package/lib/app/ReactApp.d.ts +2 -1
- package/lib/app/ReactApp.js +3 -2
- package/lib/app/ServiceApp.d.ts +22 -9
- package/lib/app/ServiceApp.js +38 -19
- package/package.json +2 -2
- package/src/app/IServiceUser.ts +6 -1
- package/src/app/ReactApp.ts +4 -2
- package/src/app/ServiceApp.ts +56 -24
package/lib/app/ReactApp.d.ts
CHANGED
|
@@ -144,8 +144,9 @@ export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends
|
|
|
144
144
|
* @param user New user
|
|
145
145
|
* @param refreshToken Refresh token
|
|
146
146
|
* @param keep Keep in local storage or not
|
|
147
|
+
* @param dispatch User state dispatch
|
|
147
148
|
*/
|
|
148
|
-
userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
|
|
149
|
+
userLogin(user: IUserData, refreshToken: string, keep?: boolean, dispatch?: boolean): void;
|
|
149
150
|
/**
|
|
150
151
|
* User logout
|
|
151
152
|
* @param clearToken Clear refresh token or not
|
package/lib/app/ReactApp.js
CHANGED
|
@@ -210,12 +210,13 @@ export class ReactApp extends CoreApp {
|
|
|
210
210
|
* @param user New user
|
|
211
211
|
* @param refreshToken Refresh token
|
|
212
212
|
* @param keep Keep in local storage or not
|
|
213
|
+
* @param dispatch User state dispatch
|
|
213
214
|
*/
|
|
214
|
-
userLogin(user, refreshToken, keep) {
|
|
215
|
+
userLogin(user, refreshToken, keep, dispatch) {
|
|
215
216
|
// Super call, set token
|
|
216
217
|
super.userLogin(user, refreshToken, keep);
|
|
217
218
|
// Dispatch action
|
|
218
|
-
if (this.userStateDispatch != null)
|
|
219
|
+
if (this.userStateDispatch != null && dispatch !== false)
|
|
219
220
|
this.userStateDispatch({
|
|
220
221
|
type: UserActionType.Login,
|
|
221
222
|
user
|
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,25 +13,23 @@ 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
19
|
/**
|
|
20
20
|
* Core system user
|
|
21
21
|
*/
|
|
22
22
|
coreUser?: ISmartERPUser;
|
|
23
|
+
/**
|
|
24
|
+
* Service passphrase
|
|
25
|
+
*/
|
|
26
|
+
servicePassphrase: string;
|
|
23
27
|
/**
|
|
24
28
|
* Constructor
|
|
25
29
|
* @param settings Settings
|
|
26
30
|
* @param name Application name
|
|
27
31
|
*/
|
|
28
32
|
constructor(settings: S, name: string);
|
|
29
|
-
/**
|
|
30
|
-
* Api init call, connect to the core Api
|
|
31
|
-
* @param data Data
|
|
32
|
-
* @returns Result
|
|
33
|
-
*/
|
|
34
|
-
protected apiInitCall(data: InitCallDto): Promise<InitCallResult | undefined>;
|
|
35
33
|
/**
|
|
36
34
|
* Go to the login page
|
|
37
35
|
*/
|
|
@@ -42,6 +40,21 @@ export declare class ServiceApp<P extends IServicePageData = IServicePageData, U
|
|
|
42
40
|
*/
|
|
43
41
|
refreshToken<D = RefreshTokenRQ>(props?: RefreshTokenProps<D>): Promise<boolean>;
|
|
44
42
|
private loginFailed;
|
|
43
|
+
/**
|
|
44
|
+
* Service decrypt message
|
|
45
|
+
* @param messageEncrypted Encrypted message
|
|
46
|
+
* @param passphrase Secret passphrase
|
|
47
|
+
* @returns Pure text
|
|
48
|
+
*/
|
|
49
|
+
serviceDecrypt(messageEncrypted: string, passphrase?: string): string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Service encrypt message
|
|
52
|
+
* @param message Message
|
|
53
|
+
* @param passphrase Secret passphrase
|
|
54
|
+
* @param iterations Iterations, 1000 times, 1 - 99
|
|
55
|
+
* @returns Result
|
|
56
|
+
*/
|
|
57
|
+
serviceEncrypt(message: string, passphrase?: string, iterations?: number): string;
|
|
45
58
|
/**
|
|
46
59
|
* Try login
|
|
47
60
|
*/
|
package/lib/app/ServiceApp.js
CHANGED
|
@@ -16,29 +16,25 @@ export class ServiceApp extends ReactApp {
|
|
|
16
16
|
*/
|
|
17
17
|
constructor(settings, name) {
|
|
18
18
|
super(settings, name);
|
|
19
|
+
/**
|
|
20
|
+
* Service passphrase
|
|
21
|
+
*/
|
|
22
|
+
this.servicePassphrase = '';
|
|
19
23
|
// Check
|
|
20
|
-
if (settings.serviceId == null || settings.
|
|
24
|
+
if (settings.serviceId == null || settings.serviceEndpoint == null) {
|
|
21
25
|
throw new Error('No service settings');
|
|
22
26
|
}
|
|
23
|
-
//
|
|
27
|
+
// Service API
|
|
24
28
|
const api = createClient();
|
|
25
|
-
api.baseUrl = settings.
|
|
29
|
+
api.baseUrl = settings.serviceEndpoint;
|
|
26
30
|
this.setApi(api);
|
|
27
|
-
this.
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Api init call, connect to the core Api
|
|
31
|
-
* @param data Data
|
|
32
|
-
* @returns Result
|
|
33
|
-
*/
|
|
34
|
-
async apiInitCall(data) {
|
|
35
|
-
return await this.coreApi.put(this.initCallApi, data);
|
|
31
|
+
this.serviceApi = api;
|
|
36
32
|
}
|
|
37
33
|
/**
|
|
38
34
|
* Go to the login page
|
|
39
35
|
*/
|
|
40
36
|
toLoginPage() {
|
|
41
|
-
const coreUrl = this.settings.
|
|
37
|
+
const coreUrl = this.settings.webUrl;
|
|
42
38
|
window.location.href =
|
|
43
39
|
coreUrl +
|
|
44
40
|
'?serviceId=' +
|
|
@@ -92,8 +88,8 @@ export class ServiceApp extends ReactApp {
|
|
|
92
88
|
// User data
|
|
93
89
|
const userData = result.data;
|
|
94
90
|
// Use core system access token to service api to exchange service access token
|
|
95
|
-
const serviceResult = await this.
|
|
96
|
-
token: userData.token
|
|
91
|
+
const serviceResult = await this.serviceApi.put('Auth/ExchangeToken', {
|
|
92
|
+
token: this.encryptEnhanced(userData.token, this.settings.serviceId.toString())
|
|
97
93
|
}, {
|
|
98
94
|
showLoading,
|
|
99
95
|
onError: (error) => {
|
|
@@ -123,7 +119,7 @@ export class ServiceApp extends ReactApp {
|
|
|
123
119
|
return true;
|
|
124
120
|
};
|
|
125
121
|
// Call API
|
|
126
|
-
const result = await this.
|
|
122
|
+
const result = await this.api.put('Auth/RefreshToken', rq, payload);
|
|
127
123
|
if (result == null)
|
|
128
124
|
return false;
|
|
129
125
|
if (!result.ok) {
|
|
@@ -172,6 +168,25 @@ export class ServiceApp extends ReactApp {
|
|
|
172
168
|
this.userUnauthorized();
|
|
173
169
|
this.toLoginPage();
|
|
174
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Service decrypt message
|
|
173
|
+
* @param messageEncrypted Encrypted message
|
|
174
|
+
* @param passphrase Secret passphrase
|
|
175
|
+
* @returns Pure text
|
|
176
|
+
*/
|
|
177
|
+
serviceDecrypt(messageEncrypted, passphrase) {
|
|
178
|
+
return this.decrypt(messageEncrypted, passphrase !== null && passphrase !== void 0 ? passphrase : this.servicePassphrase);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Service encrypt message
|
|
182
|
+
* @param message Message
|
|
183
|
+
* @param passphrase Secret passphrase
|
|
184
|
+
* @param iterations Iterations, 1000 times, 1 - 99
|
|
185
|
+
* @returns Result
|
|
186
|
+
*/
|
|
187
|
+
serviceEncrypt(message, passphrase, iterations) {
|
|
188
|
+
return this.encrypt(message, passphrase !== null && passphrase !== void 0 ? passphrase : this.servicePassphrase, iterations);
|
|
189
|
+
}
|
|
175
190
|
/**
|
|
176
191
|
* Try login
|
|
177
192
|
*/
|
|
@@ -206,11 +221,15 @@ export class ServiceApp extends ReactApp {
|
|
|
206
221
|
* @param coreUser Core system user
|
|
207
222
|
*/
|
|
208
223
|
userLoginEx(user, refreshToken, coreUser) {
|
|
224
|
+
var _a;
|
|
209
225
|
// Service user login
|
|
210
|
-
|
|
226
|
+
this.servicePassphrase =
|
|
227
|
+
(_a = this.decrypt(user.serviceDeviceId, this.settings.serviceId.toString())) !== null && _a !== void 0 ? _a : '';
|
|
228
|
+
// Keep = true, means service could hold the refresh token for long access
|
|
229
|
+
super.userLogin(user, refreshToken, true);
|
|
211
230
|
// Core system user
|
|
212
231
|
this.coreUser = coreUser;
|
|
213
|
-
//
|
|
214
|
-
this.
|
|
232
|
+
// Service API token
|
|
233
|
+
this.serviceApi.authorize(this.settings.authScheme, coreUser.token);
|
|
215
234
|
}
|
|
216
235
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.3.
|
|
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.
|
|
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",
|
package/src/app/IServiceUser.ts
CHANGED
|
@@ -3,7 +3,12 @@ import { IActionResult, IUser } from '@etsoo/appscript';
|
|
|
3
3
|
/**
|
|
4
4
|
* Service user interface
|
|
5
5
|
*/
|
|
6
|
-
export interface IServiceUser extends IUser {
|
|
6
|
+
export interface IServiceUser extends IUser {
|
|
7
|
+
/**
|
|
8
|
+
* Service device id
|
|
9
|
+
*/
|
|
10
|
+
serviceDeviceId: string;
|
|
11
|
+
}
|
|
7
12
|
|
|
8
13
|
/**
|
|
9
14
|
* Service user login result
|
package/src/app/ReactApp.ts
CHANGED
|
@@ -353,17 +353,19 @@ export class ReactApp<
|
|
|
353
353
|
* @param user New user
|
|
354
354
|
* @param refreshToken Refresh token
|
|
355
355
|
* @param keep Keep in local storage or not
|
|
356
|
+
* @param dispatch User state dispatch
|
|
356
357
|
*/
|
|
357
358
|
override userLogin(
|
|
358
359
|
user: IUserData,
|
|
359
360
|
refreshToken: string,
|
|
360
|
-
keep?: boolean
|
|
361
|
+
keep?: boolean,
|
|
362
|
+
dispatch?: boolean
|
|
361
363
|
): void {
|
|
362
364
|
// Super call, set token
|
|
363
365
|
super.userLogin(user, refreshToken, keep);
|
|
364
366
|
|
|
365
367
|
// Dispatch action
|
|
366
|
-
if (this.userStateDispatch != null)
|
|
368
|
+
if (this.userStateDispatch != null && dispatch !== false)
|
|
367
369
|
this.userStateDispatch({
|
|
368
370
|
type: UserActionType.Login,
|
|
369
371
|
user
|
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,15 +26,20 @@ 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
|
|
|
35
33
|
/**
|
|
36
34
|
* Core system user
|
|
37
35
|
*/
|
|
38
36
|
coreUser?: ISmartERPUser;
|
|
39
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Service passphrase
|
|
40
|
+
*/
|
|
41
|
+
servicePassphrase: string = '';
|
|
42
|
+
|
|
40
43
|
/**
|
|
41
44
|
* Constructor
|
|
42
45
|
* @param settings Settings
|
|
@@ -46,32 +49,23 @@ export class ServiceApp<
|
|
|
46
49
|
super(settings, name);
|
|
47
50
|
|
|
48
51
|
// Check
|
|
49
|
-
if (settings.serviceId == null || settings.
|
|
52
|
+
if (settings.serviceId == null || settings.serviceEndpoint == null) {
|
|
50
53
|
throw new Error('No service settings');
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
//
|
|
56
|
+
// Service API
|
|
54
57
|
const api = createClient();
|
|
55
|
-
api.baseUrl = settings.
|
|
58
|
+
api.baseUrl = settings.serviceEndpoint;
|
|
56
59
|
|
|
57
60
|
this.setApi(api);
|
|
58
|
-
this.
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Api init call, connect to the core Api
|
|
63
|
-
* @param data Data
|
|
64
|
-
* @returns Result
|
|
65
|
-
*/
|
|
66
|
-
protected override async apiInitCall(data: InitCallDto) {
|
|
67
|
-
return await this.coreApi.put<InitCallResult>(this.initCallApi, data);
|
|
61
|
+
this.serviceApi = api;
|
|
68
62
|
}
|
|
69
63
|
|
|
70
64
|
/**
|
|
71
65
|
* Go to the login page
|
|
72
66
|
*/
|
|
73
67
|
override toLoginPage() {
|
|
74
|
-
const coreUrl = this.settings.
|
|
68
|
+
const coreUrl = this.settings.webUrl;
|
|
75
69
|
window.location.href =
|
|
76
70
|
coreUrl +
|
|
77
71
|
'?serviceId=' +
|
|
@@ -140,10 +134,13 @@ export class ServiceApp<
|
|
|
140
134
|
const userData = result.data;
|
|
141
135
|
|
|
142
136
|
// Use core system access token to service api to exchange service access token
|
|
143
|
-
const serviceResult = await this.
|
|
137
|
+
const serviceResult = await this.serviceApi.put<ServiceLoginResult>(
|
|
144
138
|
'Auth/ExchangeToken',
|
|
145
139
|
{
|
|
146
|
-
token:
|
|
140
|
+
token: this.encryptEnhanced(
|
|
141
|
+
userData.token,
|
|
142
|
+
this.settings.serviceId.toString()
|
|
143
|
+
)
|
|
147
144
|
},
|
|
148
145
|
{
|
|
149
146
|
showLoading,
|
|
@@ -178,7 +175,7 @@ export class ServiceApp<
|
|
|
178
175
|
};
|
|
179
176
|
|
|
180
177
|
// Call API
|
|
181
|
-
const result = await this.
|
|
178
|
+
const result = await this.api.put<SmartERPLoginResult>(
|
|
182
179
|
'Auth/RefreshToken',
|
|
183
180
|
rq,
|
|
184
181
|
payload
|
|
@@ -253,6 +250,34 @@ export class ServiceApp<
|
|
|
253
250
|
this.toLoginPage();
|
|
254
251
|
}
|
|
255
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Service decrypt message
|
|
255
|
+
* @param messageEncrypted Encrypted message
|
|
256
|
+
* @param passphrase Secret passphrase
|
|
257
|
+
* @returns Pure text
|
|
258
|
+
*/
|
|
259
|
+
serviceDecrypt(messageEncrypted: string, passphrase?: string) {
|
|
260
|
+
return this.decrypt(
|
|
261
|
+
messageEncrypted,
|
|
262
|
+
passphrase ?? this.servicePassphrase
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Service encrypt message
|
|
268
|
+
* @param message Message
|
|
269
|
+
* @param passphrase Secret passphrase
|
|
270
|
+
* @param iterations Iterations, 1000 times, 1 - 99
|
|
271
|
+
* @returns Result
|
|
272
|
+
*/
|
|
273
|
+
serviceEncrypt(message: string, passphrase?: string, iterations?: number) {
|
|
274
|
+
return this.encrypt(
|
|
275
|
+
message,
|
|
276
|
+
passphrase ?? this.servicePassphrase,
|
|
277
|
+
iterations
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
256
281
|
/**
|
|
257
282
|
* Try login
|
|
258
283
|
*/
|
|
@@ -294,12 +319,19 @@ export class ServiceApp<
|
|
|
294
319
|
coreUser: ISmartERPUser
|
|
295
320
|
): void {
|
|
296
321
|
// Service user login
|
|
297
|
-
|
|
322
|
+
this.servicePassphrase =
|
|
323
|
+
this.decrypt(
|
|
324
|
+
user.serviceDeviceId,
|
|
325
|
+
this.settings.serviceId.toString()
|
|
326
|
+
) ?? '';
|
|
327
|
+
|
|
328
|
+
// Keep = true, means service could hold the refresh token for long access
|
|
329
|
+
super.userLogin(user, refreshToken, true);
|
|
298
330
|
|
|
299
331
|
// Core system user
|
|
300
332
|
this.coreUser = coreUser;
|
|
301
333
|
|
|
302
|
-
//
|
|
303
|
-
this.
|
|
334
|
+
// Service API token
|
|
335
|
+
this.serviceApi.authorize(this.settings.authScheme, coreUser.token);
|
|
304
336
|
}
|
|
305
337
|
}
|