@etsoo/react 1.3.64 → 1.3.68
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/RefreshTokenRQ.d.ts +4 -0
- package/lib/app/ServiceApp.d.ts +26 -1
- package/lib/app/ServiceApp.js +48 -3
- package/package.json +2 -2
- package/src/app/IServiceUser.ts +6 -1
- package/src/app/ReactApp.ts +4 -2
- package/src/app/RefreshTokenRQ.ts +5 -0
- package/src/app/ServiceApp.ts +69 -10
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, RefreshTokenProps } from '@etsoo/appscript';
|
|
1
|
+
import { IApi, InitCallDto, InitCallResult, RefreshTokenProps } from '@etsoo/appscript';
|
|
2
2
|
import { IServiceAppSettings } from './IServiceAppSettings';
|
|
3
3
|
import { IServicePageData } from './IServicePage';
|
|
4
4
|
import { IServiceUser } from './IServiceUser';
|
|
@@ -20,12 +20,22 @@ export declare class ServiceApp<P extends IServicePageData = IServicePageData, U
|
|
|
20
20
|
* Core system user
|
|
21
21
|
*/
|
|
22
22
|
coreUser?: ISmartERPUser;
|
|
23
|
+
/**
|
|
24
|
+
* Service device id
|
|
25
|
+
*/
|
|
26
|
+
protected serviceDeviceId: 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);
|
|
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>;
|
|
29
39
|
/**
|
|
30
40
|
* Go to the login page
|
|
31
41
|
*/
|
|
@@ -36,6 +46,21 @@ export declare class ServiceApp<P extends IServicePageData = IServicePageData, U
|
|
|
36
46
|
*/
|
|
37
47
|
refreshToken<D = RefreshTokenRQ>(props?: RefreshTokenProps<D>): Promise<boolean>;
|
|
38
48
|
private loginFailed;
|
|
49
|
+
/**
|
|
50
|
+
* Service decrypt message
|
|
51
|
+
* @param messageEncrypted Encrypted message
|
|
52
|
+
* @param passphrase Secret passphrase
|
|
53
|
+
* @returns Pure text
|
|
54
|
+
*/
|
|
55
|
+
serviceDecrypt(messageEncrypted: string, passphrase?: string): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Service encrypt message
|
|
58
|
+
* @param message Message
|
|
59
|
+
* @param passphrase Secret passphrase
|
|
60
|
+
* @param iterations Iterations, 1000 times, 1 - 99
|
|
61
|
+
* @returns Result
|
|
62
|
+
*/
|
|
63
|
+
serviceEncrypt(message: string, passphrase?: string, iterations?: number): string;
|
|
39
64
|
/**
|
|
40
65
|
* Try login
|
|
41
66
|
*/
|
package/lib/app/ServiceApp.js
CHANGED
|
@@ -16,6 +16,10 @@ export class ServiceApp extends ReactApp {
|
|
|
16
16
|
*/
|
|
17
17
|
constructor(settings, name) {
|
|
18
18
|
super(settings, name);
|
|
19
|
+
/**
|
|
20
|
+
* Service device id
|
|
21
|
+
*/
|
|
22
|
+
this.serviceDeviceId = '';
|
|
19
23
|
// Check
|
|
20
24
|
if (settings.serviceId == null || settings.coreApi == null) {
|
|
21
25
|
throw new Error('No service settings');
|
|
@@ -26,6 +30,14 @@ export class ServiceApp extends ReactApp {
|
|
|
26
30
|
this.setApi(api);
|
|
27
31
|
this.coreApi = api;
|
|
28
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);
|
|
40
|
+
}
|
|
29
41
|
/**
|
|
30
42
|
* Go to the login page
|
|
31
43
|
*/
|
|
@@ -57,6 +69,7 @@ export class ServiceApp extends ReactApp {
|
|
|
57
69
|
// Reqest data
|
|
58
70
|
// Merge additional data passed
|
|
59
71
|
const rq = {
|
|
72
|
+
deviceId: this.deviceId,
|
|
60
73
|
timezone: this.getTimeZone(),
|
|
61
74
|
...data
|
|
62
75
|
};
|
|
@@ -84,7 +97,7 @@ export class ServiceApp extends ReactApp {
|
|
|
84
97
|
const userData = result.data;
|
|
85
98
|
// Use core system access token to service api to exchange service access token
|
|
86
99
|
const serviceResult = await this.api.put('Auth/ExchangeToken', {
|
|
87
|
-
token: userData.token
|
|
100
|
+
token: this.encryptEnhanced(userData.token, this.settings.serviceId.toString())
|
|
88
101
|
}, {
|
|
89
102
|
showLoading,
|
|
90
103
|
onError: (error) => {
|
|
@@ -106,7 +119,11 @@ export class ServiceApp extends ReactApp {
|
|
|
106
119
|
failCallback(this.get('noData'));
|
|
107
120
|
return false;
|
|
108
121
|
}
|
|
122
|
+
// Login
|
|
109
123
|
this.userLoginEx(serviceResult.data, refreshToken, userData);
|
|
124
|
+
// Success callback
|
|
125
|
+
if (failCallback)
|
|
126
|
+
failCallback(true);
|
|
110
127
|
return true;
|
|
111
128
|
};
|
|
112
129
|
// Call API
|
|
@@ -124,13 +141,18 @@ export class ServiceApp extends ReactApp {
|
|
|
124
141
|
return;
|
|
125
142
|
}
|
|
126
143
|
// Set password for the action
|
|
127
|
-
rq.pwd = this.encrypt(
|
|
144
|
+
rq.pwd = this.encrypt(this.hash(pwd));
|
|
128
145
|
// Submit again
|
|
129
|
-
const result = await this.
|
|
146
|
+
const result = await this.coreApi.put('Auth/RefreshToken', rq, payload);
|
|
130
147
|
if (result == null)
|
|
131
148
|
return;
|
|
132
149
|
if (result.ok) {
|
|
133
150
|
await success(result, (loginResult) => {
|
|
151
|
+
if (loginResult === true) {
|
|
152
|
+
if (callback)
|
|
153
|
+
callback(true);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
134
156
|
const message = this.formatRefreshTokenResult(loginResult);
|
|
135
157
|
if (message)
|
|
136
158
|
this.notifier.alert(message);
|
|
@@ -154,6 +176,25 @@ export class ServiceApp extends ReactApp {
|
|
|
154
176
|
this.userUnauthorized();
|
|
155
177
|
this.toLoginPage();
|
|
156
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Service decrypt message
|
|
181
|
+
* @param messageEncrypted Encrypted message
|
|
182
|
+
* @param passphrase Secret passphrase
|
|
183
|
+
* @returns Pure text
|
|
184
|
+
*/
|
|
185
|
+
serviceDecrypt(messageEncrypted, passphrase) {
|
|
186
|
+
return this.decrypt(messageEncrypted, passphrase !== null && passphrase !== void 0 ? passphrase : this.serviceDeviceId);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Service encrypt message
|
|
190
|
+
* @param message Message
|
|
191
|
+
* @param passphrase Secret passphrase
|
|
192
|
+
* @param iterations Iterations, 1000 times, 1 - 99
|
|
193
|
+
* @returns Result
|
|
194
|
+
*/
|
|
195
|
+
serviceEncrypt(message, passphrase, iterations) {
|
|
196
|
+
return this.encrypt(message, passphrase !== null && passphrase !== void 0 ? passphrase : this.serviceDeviceId, iterations);
|
|
197
|
+
}
|
|
157
198
|
/**
|
|
158
199
|
* Try login
|
|
159
200
|
*/
|
|
@@ -165,6 +206,9 @@ export class ServiceApp extends ReactApp {
|
|
|
165
206
|
// Refresh token
|
|
166
207
|
return await this.refreshToken({
|
|
167
208
|
callback: (result) => {
|
|
209
|
+
// Success
|
|
210
|
+
if (result === true)
|
|
211
|
+
return;
|
|
168
212
|
const message = this.formatRefreshTokenResult(result);
|
|
169
213
|
if (message == null) {
|
|
170
214
|
this.loginFailed();
|
|
@@ -186,6 +230,7 @@ export class ServiceApp extends ReactApp {
|
|
|
186
230
|
*/
|
|
187
231
|
userLoginEx(user, refreshToken, coreUser) {
|
|
188
232
|
// Service user login
|
|
233
|
+
this.serviceDeviceId = user.serviceDeviceId;
|
|
189
234
|
super.userLogin(user, refreshToken, false);
|
|
190
235
|
// Core system user
|
|
191
236
|
this.coreUser = coreUser;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.68",
|
|
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.83",
|
|
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,6 +2,8 @@ import {
|
|
|
2
2
|
createClient,
|
|
3
3
|
IApi,
|
|
4
4
|
IApiPayload,
|
|
5
|
+
InitCallDto,
|
|
6
|
+
InitCallResult,
|
|
5
7
|
RefreshTokenProps,
|
|
6
8
|
RefreshTokenResult
|
|
7
9
|
} from '@etsoo/appscript';
|
|
@@ -35,6 +37,11 @@ export class ServiceApp<
|
|
|
35
37
|
*/
|
|
36
38
|
coreUser?: ISmartERPUser;
|
|
37
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Service device id
|
|
42
|
+
*/
|
|
43
|
+
protected serviceDeviceId: string = '';
|
|
44
|
+
|
|
38
45
|
/**
|
|
39
46
|
* Constructor
|
|
40
47
|
* @param settings Settings
|
|
@@ -56,6 +63,15 @@ export class ServiceApp<
|
|
|
56
63
|
this.coreApi = api;
|
|
57
64
|
}
|
|
58
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);
|
|
73
|
+
}
|
|
74
|
+
|
|
59
75
|
/**
|
|
60
76
|
* Go to the login page
|
|
61
77
|
*/
|
|
@@ -96,6 +112,7 @@ export class ServiceApp<
|
|
|
96
112
|
// Reqest data
|
|
97
113
|
// Merge additional data passed
|
|
98
114
|
const rq: RefreshTokenRQ = {
|
|
115
|
+
deviceId: this.deviceId,
|
|
99
116
|
timezone: this.getTimeZone(),
|
|
100
117
|
...data
|
|
101
118
|
};
|
|
@@ -131,7 +148,10 @@ export class ServiceApp<
|
|
|
131
148
|
const serviceResult = await this.api.put<ServiceLoginResult>(
|
|
132
149
|
'Auth/ExchangeToken',
|
|
133
150
|
{
|
|
134
|
-
token:
|
|
151
|
+
token: this.encryptEnhanced(
|
|
152
|
+
userData.token,
|
|
153
|
+
this.settings.serviceId.toString()
|
|
154
|
+
)
|
|
135
155
|
},
|
|
136
156
|
{
|
|
137
157
|
showLoading,
|
|
@@ -156,8 +176,12 @@ export class ServiceApp<
|
|
|
156
176
|
return false;
|
|
157
177
|
}
|
|
158
178
|
|
|
179
|
+
// Login
|
|
159
180
|
this.userLoginEx(serviceResult.data, refreshToken, userData);
|
|
160
181
|
|
|
182
|
+
// Success callback
|
|
183
|
+
if (failCallback) failCallback(true);
|
|
184
|
+
|
|
161
185
|
return true;
|
|
162
186
|
};
|
|
163
187
|
|
|
@@ -183,17 +207,15 @@ export class ServiceApp<
|
|
|
183
207
|
}
|
|
184
208
|
|
|
185
209
|
// Set password for the action
|
|
186
|
-
rq.pwd = this.encrypt(
|
|
187
|
-
pwd,
|
|
188
|
-
this.settings.serviceId.toString()
|
|
189
|
-
);
|
|
210
|
+
rq.pwd = this.encrypt(this.hash(pwd));
|
|
190
211
|
|
|
191
212
|
// Submit again
|
|
192
|
-
const result =
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
213
|
+
const result =
|
|
214
|
+
await this.coreApi.put<SmartERPLoginResult>(
|
|
215
|
+
'Auth/RefreshToken',
|
|
216
|
+
rq,
|
|
217
|
+
payload
|
|
218
|
+
);
|
|
197
219
|
|
|
198
220
|
if (result == null) return;
|
|
199
221
|
|
|
@@ -201,6 +223,11 @@ export class ServiceApp<
|
|
|
201
223
|
await success(
|
|
202
224
|
result,
|
|
203
225
|
(loginResult: RefreshTokenResult) => {
|
|
226
|
+
if (loginResult === true) {
|
|
227
|
+
if (callback) callback(true);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
204
231
|
const message =
|
|
205
232
|
this.formatRefreshTokenResult(
|
|
206
233
|
loginResult
|
|
@@ -235,6 +262,34 @@ export class ServiceApp<
|
|
|
235
262
|
this.toLoginPage();
|
|
236
263
|
}
|
|
237
264
|
|
|
265
|
+
/**
|
|
266
|
+
* Service decrypt message
|
|
267
|
+
* @param messageEncrypted Encrypted message
|
|
268
|
+
* @param passphrase Secret passphrase
|
|
269
|
+
* @returns Pure text
|
|
270
|
+
*/
|
|
271
|
+
serviceDecrypt(messageEncrypted: string, passphrase?: string) {
|
|
272
|
+
return this.decrypt(
|
|
273
|
+
messageEncrypted,
|
|
274
|
+
passphrase ?? this.serviceDeviceId
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Service encrypt message
|
|
280
|
+
* @param message Message
|
|
281
|
+
* @param passphrase Secret passphrase
|
|
282
|
+
* @param iterations Iterations, 1000 times, 1 - 99
|
|
283
|
+
* @returns Result
|
|
284
|
+
*/
|
|
285
|
+
serviceEncrypt(message: string, passphrase?: string, iterations?: number) {
|
|
286
|
+
return this.encrypt(
|
|
287
|
+
message,
|
|
288
|
+
passphrase ?? this.serviceDeviceId,
|
|
289
|
+
iterations
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
238
293
|
/**
|
|
239
294
|
* Try login
|
|
240
295
|
*/
|
|
@@ -246,6 +301,9 @@ export class ServiceApp<
|
|
|
246
301
|
// Refresh token
|
|
247
302
|
return await this.refreshToken({
|
|
248
303
|
callback: (result) => {
|
|
304
|
+
// Success
|
|
305
|
+
if (result === true) return;
|
|
306
|
+
|
|
249
307
|
const message = this.formatRefreshTokenResult(result);
|
|
250
308
|
if (message == null) {
|
|
251
309
|
this.loginFailed();
|
|
@@ -273,6 +331,7 @@ export class ServiceApp<
|
|
|
273
331
|
coreUser: ISmartERPUser
|
|
274
332
|
): void {
|
|
275
333
|
// Service user login
|
|
334
|
+
this.serviceDeviceId = user.serviceDeviceId;
|
|
276
335
|
super.userLogin(user, refreshToken, false);
|
|
277
336
|
|
|
278
337
|
// Core system user
|