@etsoo/react 1.3.67 → 1.3.72
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/ServiceApp.d.ts +27 -14
- package/lib/app/ServiceApp.js +44 -25
- package/package.json +2 -2
- package/src/app/IServiceUser.ts +6 -1
- package/src/app/ServiceApp.ts +65 -33
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
|
+
* Service user
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
serviceUser?: 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,15 +40,30 @@ 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
|
*/
|
|
48
61
|
tryLogin<D extends {} = {}>(data?: D): Promise<boolean>;
|
|
49
62
|
/**
|
|
50
63
|
* User login extended
|
|
51
|
-
* @param user
|
|
64
|
+
* @param user Core system user
|
|
52
65
|
* @param refreshToken Refresh token
|
|
53
|
-
* @param
|
|
66
|
+
* @param serviceUser Service user
|
|
54
67
|
*/
|
|
55
|
-
userLoginEx(user:
|
|
68
|
+
userLoginEx(user: ISmartERPUser, refreshToken: string, serviceUser: IServiceUser): void;
|
|
56
69
|
}
|
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) => {
|
|
@@ -116,14 +112,14 @@ export class ServiceApp extends ReactApp {
|
|
|
116
112
|
return false;
|
|
117
113
|
}
|
|
118
114
|
// Login
|
|
119
|
-
this.userLoginEx(
|
|
115
|
+
this.userLoginEx(userData, refreshToken, serviceResult.data);
|
|
120
116
|
// Success callback
|
|
121
117
|
if (failCallback)
|
|
122
118
|
failCallback(true);
|
|
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
|
*/
|
|
@@ -201,16 +216,20 @@ export class ServiceApp extends ReactApp {
|
|
|
201
216
|
}
|
|
202
217
|
/**
|
|
203
218
|
* User login extended
|
|
204
|
-
* @param user
|
|
219
|
+
* @param user Core system user
|
|
205
220
|
* @param refreshToken Refresh token
|
|
206
|
-
* @param
|
|
221
|
+
* @param serviceUser Service user
|
|
207
222
|
*/
|
|
208
|
-
userLoginEx(user, refreshToken,
|
|
223
|
+
userLoginEx(user, refreshToken, serviceUser) {
|
|
224
|
+
var _a;
|
|
209
225
|
// Service user login
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
226
|
+
this.servicePassphrase =
|
|
227
|
+
(_a = this.decrypt(serviceUser.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);
|
|
230
|
+
// Service user
|
|
231
|
+
this.serviceUser = serviceUser;
|
|
232
|
+
// Service API token
|
|
233
|
+
this.serviceApi.authorize(this.settings.authScheme, serviceUser.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.72",
|
|
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/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,14 +26,19 @@ 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
|
+
* Service user
|
|
37
35
|
*/
|
|
38
|
-
|
|
36
|
+
serviceUser?: ISmartERPUser;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Service passphrase
|
|
40
|
+
*/
|
|
41
|
+
servicePassphrase: string = '';
|
|
39
42
|
|
|
40
43
|
/**
|
|
41
44
|
* Constructor
|
|
@@ -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,
|
|
@@ -169,7 +166,7 @@ export class ServiceApp<
|
|
|
169
166
|
}
|
|
170
167
|
|
|
171
168
|
// Login
|
|
172
|
-
this.userLoginEx(
|
|
169
|
+
this.userLoginEx(userData, refreshToken, serviceResult.data);
|
|
173
170
|
|
|
174
171
|
// Success callback
|
|
175
172
|
if (failCallback) failCallback(true);
|
|
@@ -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
|
*/
|
|
@@ -284,22 +309,29 @@ export class ServiceApp<
|
|
|
284
309
|
|
|
285
310
|
/**
|
|
286
311
|
* User login extended
|
|
287
|
-
* @param user
|
|
312
|
+
* @param user Core system user
|
|
288
313
|
* @param refreshToken Refresh token
|
|
289
|
-
* @param
|
|
314
|
+
* @param serviceUser Service user
|
|
290
315
|
*/
|
|
291
316
|
userLoginEx(
|
|
292
|
-
user:
|
|
317
|
+
user: ISmartERPUser,
|
|
293
318
|
refreshToken: string,
|
|
294
|
-
|
|
319
|
+
serviceUser: IServiceUser
|
|
295
320
|
): void {
|
|
296
321
|
// Service user login
|
|
297
|
-
|
|
322
|
+
this.servicePassphrase =
|
|
323
|
+
this.decrypt(
|
|
324
|
+
serviceUser.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
|
-
//
|
|
300
|
-
this.
|
|
331
|
+
// Service user
|
|
332
|
+
this.serviceUser = serviceUser;
|
|
301
333
|
|
|
302
|
-
//
|
|
303
|
-
this.
|
|
334
|
+
// Service API token
|
|
335
|
+
this.serviceApi.authorize(this.settings.authScheme, serviceUser.token);
|
|
304
336
|
}
|
|
305
337
|
}
|