@etsoo/appscript 1.1.72 → 1.1.76
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/cjs/app/CoreApp.d.ts +22 -12
- package/lib/cjs/app/CoreApp.js +46 -19
- package/lib/mjs/app/CoreApp.d.ts +22 -12
- package/lib/mjs/app/CoreApp.js +46 -19
- package/package.json +1 -1
- package/src/app/CoreApp.ts +65 -43
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -68,6 +68,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
68
68
|
* Currency, like USD for US dollar
|
|
69
69
|
*/
|
|
70
70
|
readonly currency: string;
|
|
71
|
+
/**
|
|
72
|
+
* Device id
|
|
73
|
+
*/
|
|
74
|
+
readonly deviceId: string;
|
|
71
75
|
/**
|
|
72
76
|
* Country or region, like CN
|
|
73
77
|
*/
|
|
@@ -101,9 +105,8 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
101
105
|
* Authorize
|
|
102
106
|
* @param token New token
|
|
103
107
|
* @param refreshToken Refresh token
|
|
104
|
-
* @param keep Keep in local storage or not
|
|
105
108
|
*/
|
|
106
|
-
authorize(token?: string, refreshToken?: string
|
|
109
|
+
authorize(token?: string, refreshToken?: string): void;
|
|
107
110
|
/**
|
|
108
111
|
* Change country or region
|
|
109
112
|
* @param region New country or region
|
|
@@ -114,6 +117,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
114
117
|
* @param culture New culture definition
|
|
115
118
|
*/
|
|
116
119
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
120
|
+
/**
|
|
121
|
+
* Clear cached token
|
|
122
|
+
*/
|
|
123
|
+
clearCacheToken(): void;
|
|
117
124
|
/**
|
|
118
125
|
* Decrypt message
|
|
119
126
|
* @param messageEncrypted Encrypted message
|
|
@@ -295,9 +302,8 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
295
302
|
* User login
|
|
296
303
|
* @param user User data
|
|
297
304
|
* @param refreshToken Refresh token
|
|
298
|
-
* @param keep Keep in local storage or not
|
|
299
305
|
*/
|
|
300
|
-
userLogin(user: IUserData, refreshToken: string
|
|
306
|
+
userLogin(user: IUserData, refreshToken: string): void;
|
|
301
307
|
/**
|
|
302
308
|
* User logout
|
|
303
309
|
* @param clearToken Clear refresh token or not
|
|
@@ -349,6 +355,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
349
355
|
* Country or region, like CN
|
|
350
356
|
*/
|
|
351
357
|
get region(): string;
|
|
358
|
+
private _deviceId;
|
|
359
|
+
/**
|
|
360
|
+
* Country or region, like CN
|
|
361
|
+
*/
|
|
362
|
+
get deviceId(): string;
|
|
363
|
+
protected set deviceId(value: string);
|
|
352
364
|
/**
|
|
353
365
|
* Label delegate
|
|
354
366
|
*/
|
|
@@ -389,10 +401,6 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
389
401
|
* Device id field name
|
|
390
402
|
*/
|
|
391
403
|
protected deviceIdField: string;
|
|
392
|
-
/**
|
|
393
|
-
* Device id
|
|
394
|
-
*/
|
|
395
|
-
protected deviceId: string;
|
|
396
404
|
/**
|
|
397
405
|
* Passphrase for encryption
|
|
398
406
|
*/
|
|
@@ -432,9 +440,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
432
440
|
* Authorize
|
|
433
441
|
* @param token New token
|
|
434
442
|
* @param refreshToken Refresh token
|
|
435
|
-
* @param keep Keep in local storage or not
|
|
436
443
|
*/
|
|
437
|
-
authorize(token?: string, refreshToken?: string
|
|
444
|
+
authorize(token?: string, refreshToken?: string): void;
|
|
438
445
|
/**
|
|
439
446
|
* Change country or region
|
|
440
447
|
* @param regionId New country or region
|
|
@@ -445,6 +452,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
445
452
|
* @param culture New culture definition
|
|
446
453
|
*/
|
|
447
454
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
455
|
+
/**
|
|
456
|
+
* Clear cached token
|
|
457
|
+
*/
|
|
458
|
+
clearCacheToken(): void;
|
|
448
459
|
/**
|
|
449
460
|
* Decrypt message
|
|
450
461
|
* @param messageEncrypted Encrypted message
|
|
@@ -638,9 +649,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
638
649
|
* User login
|
|
639
650
|
* @param user User data
|
|
640
651
|
* @param refreshToken Refresh token
|
|
641
|
-
* @param keep Keep in local storage or not
|
|
642
652
|
*/
|
|
643
|
-
userLogin(user: IUserData, refreshToken: string
|
|
653
|
+
userLogin(user: IUserData, refreshToken: string): void;
|
|
644
654
|
/**
|
|
645
655
|
* User logout
|
|
646
656
|
* @param clearToken Clear refresh token or not
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -20,6 +20,7 @@ class CoreApp {
|
|
|
20
20
|
* @param name Application name
|
|
21
21
|
*/
|
|
22
22
|
constructor(settings, api, notifier, name) {
|
|
23
|
+
this._deviceId = '***';
|
|
23
24
|
/**
|
|
24
25
|
* Response token header field name
|
|
25
26
|
*/
|
|
@@ -72,6 +73,15 @@ class CoreApp {
|
|
|
72
73
|
get region() {
|
|
73
74
|
return this._region;
|
|
74
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Country or region, like CN
|
|
78
|
+
*/
|
|
79
|
+
get deviceId() {
|
|
80
|
+
return this._deviceId;
|
|
81
|
+
}
|
|
82
|
+
set deviceId(value) {
|
|
83
|
+
this._deviceId = value;
|
|
84
|
+
}
|
|
75
85
|
/**
|
|
76
86
|
* Label delegate
|
|
77
87
|
*/
|
|
@@ -154,6 +164,8 @@ class CoreApp {
|
|
|
154
164
|
}
|
|
155
165
|
if (callback)
|
|
156
166
|
callback(false);
|
|
167
|
+
// Clear device id
|
|
168
|
+
shared_1.StorageUtils.setLocalData(this.deviceIdField, null);
|
|
157
169
|
return;
|
|
158
170
|
}
|
|
159
171
|
this.initCallUpdate(result.data, data.timestamp);
|
|
@@ -185,12 +197,21 @@ class CoreApp {
|
|
|
185
197
|
const fields = this.initCallUpdateFields();
|
|
186
198
|
for (const field of fields) {
|
|
187
199
|
const currentValue = shared_1.StorageUtils.getLocalData(field, '');
|
|
188
|
-
if (currentValue === ''
|
|
200
|
+
if (currentValue === '')
|
|
189
201
|
continue;
|
|
190
|
-
const
|
|
191
|
-
|
|
202
|
+
const enhanced = currentValue.indexOf('!') >= 8;
|
|
203
|
+
let newValueSource = null;
|
|
204
|
+
if (enhanced) {
|
|
205
|
+
newValueSource = this.decryptEnhanced(currentValue, prev, 12);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
newValueSource = this.decrypt(currentValue, prev);
|
|
209
|
+
}
|
|
210
|
+
if (newValueSource == null || newValueSource === '')
|
|
192
211
|
continue;
|
|
193
|
-
const newValue =
|
|
212
|
+
const newValue = enhanced
|
|
213
|
+
? this.encryptEnhanced(newValueSource)
|
|
214
|
+
: this.encrypt(newValueSource);
|
|
194
215
|
shared_1.StorageUtils.setLocalData(field, newValue);
|
|
195
216
|
}
|
|
196
217
|
}
|
|
@@ -200,7 +221,7 @@ class CoreApp {
|
|
|
200
221
|
* @returns Fields
|
|
201
222
|
*/
|
|
202
223
|
initCallUpdateFields() {
|
|
203
|
-
return [];
|
|
224
|
+
return [this.headerTokenField];
|
|
204
225
|
}
|
|
205
226
|
/**
|
|
206
227
|
* Alert action result
|
|
@@ -214,17 +235,17 @@ class CoreApp {
|
|
|
214
235
|
* Authorize
|
|
215
236
|
* @param token New token
|
|
216
237
|
* @param refreshToken Refresh token
|
|
217
|
-
* @param keep Keep in local storage or not
|
|
218
238
|
*/
|
|
219
|
-
authorize(token, refreshToken
|
|
239
|
+
authorize(token, refreshToken) {
|
|
220
240
|
// State, when token is null, means logout
|
|
221
241
|
this.authorized = token != null;
|
|
222
242
|
// Token
|
|
223
243
|
this.api.authorize(this.settings.authScheme, token);
|
|
224
244
|
// Cover the current value
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
|
|
245
|
+
if (refreshToken !== '') {
|
|
246
|
+
if (refreshToken != null)
|
|
247
|
+
refreshToken = this.encrypt(refreshToken);
|
|
248
|
+
shared_1.StorageUtils.setLocalData(this.headerTokenField, refreshToken);
|
|
228
249
|
}
|
|
229
250
|
// Reset tryLogin state
|
|
230
251
|
this._isTryingLogin = false;
|
|
@@ -290,6 +311,12 @@ class CoreApp {
|
|
|
290
311
|
region.name = AddressUtils_1.AddressUtils.getRegionLabel(id, this.labelDelegate);
|
|
291
312
|
});
|
|
292
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Clear cached token
|
|
316
|
+
*/
|
|
317
|
+
clearCacheToken() {
|
|
318
|
+
shared_1.StorageUtils.setLocalData(this.headerTokenField, null);
|
|
319
|
+
}
|
|
293
320
|
/**
|
|
294
321
|
* Decrypt message
|
|
295
322
|
* @param messageEncrypted Encrypted message
|
|
@@ -533,12 +560,13 @@ class CoreApp {
|
|
|
533
560
|
* @returns Cached token
|
|
534
561
|
*/
|
|
535
562
|
getCacheToken() {
|
|
536
|
-
|
|
537
|
-
if (refreshToken === '')
|
|
538
|
-
refreshToken = shared_1.StorageUtils.getSessionData(this.headerTokenField, '');
|
|
563
|
+
const refreshToken = shared_1.StorageUtils.getLocalData(this.headerTokenField, '');
|
|
539
564
|
if (refreshToken === '')
|
|
540
565
|
return null;
|
|
541
|
-
|
|
566
|
+
const result = this.decrypt(refreshToken);
|
|
567
|
+
if (result == undefined)
|
|
568
|
+
return null;
|
|
569
|
+
return result;
|
|
542
570
|
}
|
|
543
571
|
/**
|
|
544
572
|
* Get all regions
|
|
@@ -736,24 +764,23 @@ class CoreApp {
|
|
|
736
764
|
* User login
|
|
737
765
|
* @param user User data
|
|
738
766
|
* @param refreshToken Refresh token
|
|
739
|
-
* @param keep Keep in local storage or not
|
|
740
767
|
*/
|
|
741
|
-
userLogin(user, refreshToken
|
|
768
|
+
userLogin(user, refreshToken) {
|
|
742
769
|
this.userData = user;
|
|
743
|
-
this.authorize(user.token, refreshToken
|
|
770
|
+
this.authorize(user.token, refreshToken);
|
|
744
771
|
}
|
|
745
772
|
/**
|
|
746
773
|
* User logout
|
|
747
774
|
* @param clearToken Clear refresh token or not
|
|
748
775
|
*/
|
|
749
776
|
userLogout(clearToken = true) {
|
|
750
|
-
this.authorize(undefined,
|
|
777
|
+
this.authorize(undefined, clearToken ? undefined : '');
|
|
751
778
|
}
|
|
752
779
|
/**
|
|
753
780
|
* User unauthorized
|
|
754
781
|
*/
|
|
755
782
|
userUnauthorized() {
|
|
756
|
-
this.authorize(undefined, undefined
|
|
783
|
+
this.authorize(undefined, undefined);
|
|
757
784
|
}
|
|
758
785
|
/**
|
|
759
786
|
* Show warning message
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -68,6 +68,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
68
68
|
* Currency, like USD for US dollar
|
|
69
69
|
*/
|
|
70
70
|
readonly currency: string;
|
|
71
|
+
/**
|
|
72
|
+
* Device id
|
|
73
|
+
*/
|
|
74
|
+
readonly deviceId: string;
|
|
71
75
|
/**
|
|
72
76
|
* Country or region, like CN
|
|
73
77
|
*/
|
|
@@ -101,9 +105,8 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
101
105
|
* Authorize
|
|
102
106
|
* @param token New token
|
|
103
107
|
* @param refreshToken Refresh token
|
|
104
|
-
* @param keep Keep in local storage or not
|
|
105
108
|
*/
|
|
106
|
-
authorize(token?: string, refreshToken?: string
|
|
109
|
+
authorize(token?: string, refreshToken?: string): void;
|
|
107
110
|
/**
|
|
108
111
|
* Change country or region
|
|
109
112
|
* @param region New country or region
|
|
@@ -114,6 +117,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
114
117
|
* @param culture New culture definition
|
|
115
118
|
*/
|
|
116
119
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
120
|
+
/**
|
|
121
|
+
* Clear cached token
|
|
122
|
+
*/
|
|
123
|
+
clearCacheToken(): void;
|
|
117
124
|
/**
|
|
118
125
|
* Decrypt message
|
|
119
126
|
* @param messageEncrypted Encrypted message
|
|
@@ -295,9 +302,8 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
295
302
|
* User login
|
|
296
303
|
* @param user User data
|
|
297
304
|
* @param refreshToken Refresh token
|
|
298
|
-
* @param keep Keep in local storage or not
|
|
299
305
|
*/
|
|
300
|
-
userLogin(user: IUserData, refreshToken: string
|
|
306
|
+
userLogin(user: IUserData, refreshToken: string): void;
|
|
301
307
|
/**
|
|
302
308
|
* User logout
|
|
303
309
|
* @param clearToken Clear refresh token or not
|
|
@@ -349,6 +355,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
349
355
|
* Country or region, like CN
|
|
350
356
|
*/
|
|
351
357
|
get region(): string;
|
|
358
|
+
private _deviceId;
|
|
359
|
+
/**
|
|
360
|
+
* Country or region, like CN
|
|
361
|
+
*/
|
|
362
|
+
get deviceId(): string;
|
|
363
|
+
protected set deviceId(value: string);
|
|
352
364
|
/**
|
|
353
365
|
* Label delegate
|
|
354
366
|
*/
|
|
@@ -389,10 +401,6 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
389
401
|
* Device id field name
|
|
390
402
|
*/
|
|
391
403
|
protected deviceIdField: string;
|
|
392
|
-
/**
|
|
393
|
-
* Device id
|
|
394
|
-
*/
|
|
395
|
-
protected deviceId: string;
|
|
396
404
|
/**
|
|
397
405
|
* Passphrase for encryption
|
|
398
406
|
*/
|
|
@@ -432,9 +440,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
432
440
|
* Authorize
|
|
433
441
|
* @param token New token
|
|
434
442
|
* @param refreshToken Refresh token
|
|
435
|
-
* @param keep Keep in local storage or not
|
|
436
443
|
*/
|
|
437
|
-
authorize(token?: string, refreshToken?: string
|
|
444
|
+
authorize(token?: string, refreshToken?: string): void;
|
|
438
445
|
/**
|
|
439
446
|
* Change country or region
|
|
440
447
|
* @param regionId New country or region
|
|
@@ -445,6 +452,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
445
452
|
* @param culture New culture definition
|
|
446
453
|
*/
|
|
447
454
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
455
|
+
/**
|
|
456
|
+
* Clear cached token
|
|
457
|
+
*/
|
|
458
|
+
clearCacheToken(): void;
|
|
448
459
|
/**
|
|
449
460
|
* Decrypt message
|
|
450
461
|
* @param messageEncrypted Encrypted message
|
|
@@ -638,9 +649,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
638
649
|
* User login
|
|
639
650
|
* @param user User data
|
|
640
651
|
* @param refreshToken Refresh token
|
|
641
|
-
* @param keep Keep in local storage or not
|
|
642
652
|
*/
|
|
643
|
-
userLogin(user: IUserData, refreshToken: string
|
|
653
|
+
userLogin(user: IUserData, refreshToken: string): void;
|
|
644
654
|
/**
|
|
645
655
|
* User logout
|
|
646
656
|
* @param clearToken Clear refresh token or not
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -17,6 +17,7 @@ export class CoreApp {
|
|
|
17
17
|
* @param name Application name
|
|
18
18
|
*/
|
|
19
19
|
constructor(settings, api, notifier, name) {
|
|
20
|
+
this._deviceId = '***';
|
|
20
21
|
/**
|
|
21
22
|
* Response token header field name
|
|
22
23
|
*/
|
|
@@ -69,6 +70,15 @@ export class CoreApp {
|
|
|
69
70
|
get region() {
|
|
70
71
|
return this._region;
|
|
71
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Country or region, like CN
|
|
75
|
+
*/
|
|
76
|
+
get deviceId() {
|
|
77
|
+
return this._deviceId;
|
|
78
|
+
}
|
|
79
|
+
set deviceId(value) {
|
|
80
|
+
this._deviceId = value;
|
|
81
|
+
}
|
|
72
82
|
/**
|
|
73
83
|
* Label delegate
|
|
74
84
|
*/
|
|
@@ -151,6 +161,8 @@ export class CoreApp {
|
|
|
151
161
|
}
|
|
152
162
|
if (callback)
|
|
153
163
|
callback(false);
|
|
164
|
+
// Clear device id
|
|
165
|
+
StorageUtils.setLocalData(this.deviceIdField, null);
|
|
154
166
|
return;
|
|
155
167
|
}
|
|
156
168
|
this.initCallUpdate(result.data, data.timestamp);
|
|
@@ -182,12 +194,21 @@ export class CoreApp {
|
|
|
182
194
|
const fields = this.initCallUpdateFields();
|
|
183
195
|
for (const field of fields) {
|
|
184
196
|
const currentValue = StorageUtils.getLocalData(field, '');
|
|
185
|
-
if (currentValue === ''
|
|
197
|
+
if (currentValue === '')
|
|
186
198
|
continue;
|
|
187
|
-
const
|
|
188
|
-
|
|
199
|
+
const enhanced = currentValue.indexOf('!') >= 8;
|
|
200
|
+
let newValueSource = null;
|
|
201
|
+
if (enhanced) {
|
|
202
|
+
newValueSource = this.decryptEnhanced(currentValue, prev, 12);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
newValueSource = this.decrypt(currentValue, prev);
|
|
206
|
+
}
|
|
207
|
+
if (newValueSource == null || newValueSource === '')
|
|
189
208
|
continue;
|
|
190
|
-
const newValue =
|
|
209
|
+
const newValue = enhanced
|
|
210
|
+
? this.encryptEnhanced(newValueSource)
|
|
211
|
+
: this.encrypt(newValueSource);
|
|
191
212
|
StorageUtils.setLocalData(field, newValue);
|
|
192
213
|
}
|
|
193
214
|
}
|
|
@@ -197,7 +218,7 @@ export class CoreApp {
|
|
|
197
218
|
* @returns Fields
|
|
198
219
|
*/
|
|
199
220
|
initCallUpdateFields() {
|
|
200
|
-
return [];
|
|
221
|
+
return [this.headerTokenField];
|
|
201
222
|
}
|
|
202
223
|
/**
|
|
203
224
|
* Alert action result
|
|
@@ -211,17 +232,17 @@ export class CoreApp {
|
|
|
211
232
|
* Authorize
|
|
212
233
|
* @param token New token
|
|
213
234
|
* @param refreshToken Refresh token
|
|
214
|
-
* @param keep Keep in local storage or not
|
|
215
235
|
*/
|
|
216
|
-
authorize(token, refreshToken
|
|
236
|
+
authorize(token, refreshToken) {
|
|
217
237
|
// State, when token is null, means logout
|
|
218
238
|
this.authorized = token != null;
|
|
219
239
|
// Token
|
|
220
240
|
this.api.authorize(this.settings.authScheme, token);
|
|
221
241
|
// Cover the current value
|
|
222
|
-
if (
|
|
223
|
-
|
|
224
|
-
|
|
242
|
+
if (refreshToken !== '') {
|
|
243
|
+
if (refreshToken != null)
|
|
244
|
+
refreshToken = this.encrypt(refreshToken);
|
|
245
|
+
StorageUtils.setLocalData(this.headerTokenField, refreshToken);
|
|
225
246
|
}
|
|
226
247
|
// Reset tryLogin state
|
|
227
248
|
this._isTryingLogin = false;
|
|
@@ -287,6 +308,12 @@ export class CoreApp {
|
|
|
287
308
|
region.name = AddressUtils.getRegionLabel(id, this.labelDelegate);
|
|
288
309
|
});
|
|
289
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Clear cached token
|
|
313
|
+
*/
|
|
314
|
+
clearCacheToken() {
|
|
315
|
+
StorageUtils.setLocalData(this.headerTokenField, null);
|
|
316
|
+
}
|
|
290
317
|
/**
|
|
291
318
|
* Decrypt message
|
|
292
319
|
* @param messageEncrypted Encrypted message
|
|
@@ -530,12 +557,13 @@ export class CoreApp {
|
|
|
530
557
|
* @returns Cached token
|
|
531
558
|
*/
|
|
532
559
|
getCacheToken() {
|
|
533
|
-
|
|
534
|
-
if (refreshToken === '')
|
|
535
|
-
refreshToken = StorageUtils.getSessionData(this.headerTokenField, '');
|
|
560
|
+
const refreshToken = StorageUtils.getLocalData(this.headerTokenField, '');
|
|
536
561
|
if (refreshToken === '')
|
|
537
562
|
return null;
|
|
538
|
-
|
|
563
|
+
const result = this.decrypt(refreshToken);
|
|
564
|
+
if (result == undefined)
|
|
565
|
+
return null;
|
|
566
|
+
return result;
|
|
539
567
|
}
|
|
540
568
|
/**
|
|
541
569
|
* Get all regions
|
|
@@ -733,24 +761,23 @@ export class CoreApp {
|
|
|
733
761
|
* User login
|
|
734
762
|
* @param user User data
|
|
735
763
|
* @param refreshToken Refresh token
|
|
736
|
-
* @param keep Keep in local storage or not
|
|
737
764
|
*/
|
|
738
|
-
userLogin(user, refreshToken
|
|
765
|
+
userLogin(user, refreshToken) {
|
|
739
766
|
this.userData = user;
|
|
740
|
-
this.authorize(user.token, refreshToken
|
|
767
|
+
this.authorize(user.token, refreshToken);
|
|
741
768
|
}
|
|
742
769
|
/**
|
|
743
770
|
* User logout
|
|
744
771
|
* @param clearToken Clear refresh token or not
|
|
745
772
|
*/
|
|
746
773
|
userLogout(clearToken = true) {
|
|
747
|
-
this.authorize(undefined,
|
|
774
|
+
this.authorize(undefined, clearToken ? undefined : '');
|
|
748
775
|
}
|
|
749
776
|
/**
|
|
750
777
|
* User unauthorized
|
|
751
778
|
*/
|
|
752
779
|
userUnauthorized() {
|
|
753
|
-
this.authorize(undefined, undefined
|
|
780
|
+
this.authorize(undefined, undefined);
|
|
754
781
|
}
|
|
755
782
|
/**
|
|
756
783
|
* Show warning message
|
package/package.json
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -117,6 +117,11 @@ export interface ICoreApp<
|
|
|
117
117
|
*/
|
|
118
118
|
readonly currency: string;
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Device id
|
|
122
|
+
*/
|
|
123
|
+
readonly deviceId: string;
|
|
124
|
+
|
|
120
125
|
/**
|
|
121
126
|
* Country or region, like CN
|
|
122
127
|
*/
|
|
@@ -157,9 +162,8 @@ export interface ICoreApp<
|
|
|
157
162
|
* Authorize
|
|
158
163
|
* @param token New token
|
|
159
164
|
* @param refreshToken Refresh token
|
|
160
|
-
* @param keep Keep in local storage or not
|
|
161
165
|
*/
|
|
162
|
-
authorize(token?: string, refreshToken?: string
|
|
166
|
+
authorize(token?: string, refreshToken?: string): void;
|
|
163
167
|
|
|
164
168
|
/**
|
|
165
169
|
* Change country or region
|
|
@@ -173,6 +177,11 @@ export interface ICoreApp<
|
|
|
173
177
|
*/
|
|
174
178
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
175
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Clear cached token
|
|
182
|
+
*/
|
|
183
|
+
clearCacheToken(): void;
|
|
184
|
+
|
|
176
185
|
/**
|
|
177
186
|
* Decrypt message
|
|
178
187
|
* @param messageEncrypted Encrypted message
|
|
@@ -402,9 +411,8 @@ export interface ICoreApp<
|
|
|
402
411
|
* User login
|
|
403
412
|
* @param user User data
|
|
404
413
|
* @param refreshToken Refresh token
|
|
405
|
-
* @param keep Keep in local storage or not
|
|
406
414
|
*/
|
|
407
|
-
userLogin(user: IUserData, refreshToken: string
|
|
415
|
+
userLogin(user: IUserData, refreshToken: string): void;
|
|
408
416
|
|
|
409
417
|
/**
|
|
410
418
|
* User logout
|
|
@@ -478,6 +486,17 @@ export abstract class CoreApp<
|
|
|
478
486
|
return this._region;
|
|
479
487
|
}
|
|
480
488
|
|
|
489
|
+
private _deviceId: string = '***';
|
|
490
|
+
/**
|
|
491
|
+
* Country or region, like CN
|
|
492
|
+
*/
|
|
493
|
+
get deviceId() {
|
|
494
|
+
return this._deviceId;
|
|
495
|
+
}
|
|
496
|
+
protected set deviceId(value: string) {
|
|
497
|
+
this._deviceId = value;
|
|
498
|
+
}
|
|
499
|
+
|
|
481
500
|
/**
|
|
482
501
|
* Label delegate
|
|
483
502
|
*/
|
|
@@ -537,11 +556,6 @@ export abstract class CoreApp<
|
|
|
537
556
|
*/
|
|
538
557
|
protected deviceIdField: string = 'SmartERPDeviceId';
|
|
539
558
|
|
|
540
|
-
/**
|
|
541
|
-
* Device id
|
|
542
|
-
*/
|
|
543
|
-
protected deviceId: string;
|
|
544
|
-
|
|
545
559
|
/**
|
|
546
560
|
* Passphrase for encryption
|
|
547
561
|
*/
|
|
@@ -658,6 +672,9 @@ export abstract class CoreApp<
|
|
|
658
672
|
|
|
659
673
|
if (callback) callback(false);
|
|
660
674
|
|
|
675
|
+
// Clear device id
|
|
676
|
+
StorageUtils.setLocalData(this.deviceIdField, null);
|
|
677
|
+
|
|
661
678
|
return;
|
|
662
679
|
}
|
|
663
680
|
|
|
@@ -700,17 +717,27 @@ export abstract class CoreApp<
|
|
|
700
717
|
field,
|
|
701
718
|
''
|
|
702
719
|
);
|
|
703
|
-
if (currentValue === ''
|
|
704
|
-
continue;
|
|
720
|
+
if (currentValue === '') continue;
|
|
705
721
|
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
722
|
+
const enhanced = currentValue.indexOf('!') >= 8;
|
|
723
|
+
let newValueSource = null;
|
|
724
|
+
|
|
725
|
+
if (enhanced) {
|
|
726
|
+
newValueSource = this.decryptEnhanced(
|
|
727
|
+
currentValue,
|
|
728
|
+
prev,
|
|
729
|
+
12
|
|
730
|
+
);
|
|
731
|
+
} else {
|
|
732
|
+
newValueSource = this.decrypt(currentValue, prev);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
if (newValueSource == null || newValueSource === '') continue;
|
|
736
|
+
|
|
737
|
+
const newValue = enhanced
|
|
738
|
+
? this.encryptEnhanced(newValueSource)
|
|
739
|
+
: this.encrypt(newValueSource);
|
|
712
740
|
|
|
713
|
-
const newValue = this.encryptEnhanced(newValueSource);
|
|
714
741
|
StorageUtils.setLocalData(field, newValue);
|
|
715
742
|
}
|
|
716
743
|
}
|
|
@@ -721,7 +748,7 @@ export abstract class CoreApp<
|
|
|
721
748
|
* @returns Fields
|
|
722
749
|
*/
|
|
723
750
|
protected initCallUpdateFields(): string[] {
|
|
724
|
-
return [];
|
|
751
|
+
return [this.headerTokenField];
|
|
725
752
|
}
|
|
726
753
|
|
|
727
754
|
/**
|
|
@@ -737,9 +764,8 @@ export abstract class CoreApp<
|
|
|
737
764
|
* Authorize
|
|
738
765
|
* @param token New token
|
|
739
766
|
* @param refreshToken Refresh token
|
|
740
|
-
* @param keep Keep in local storage or not
|
|
741
767
|
*/
|
|
742
|
-
authorize(token?: string, refreshToken?: string
|
|
768
|
+
authorize(token?: string, refreshToken?: string) {
|
|
743
769
|
// State, when token is null, means logout
|
|
744
770
|
this.authorized = token != null;
|
|
745
771
|
|
|
@@ -747,17 +773,10 @@ export abstract class CoreApp<
|
|
|
747
773
|
this.api.authorize(this.settings.authScheme, token);
|
|
748
774
|
|
|
749
775
|
// Cover the current value
|
|
750
|
-
if (
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
keep ? refreshToken : undefined
|
|
754
|
-
);
|
|
755
|
-
StorageUtils.setSessionData(
|
|
756
|
-
this.headerTokenField,
|
|
757
|
-
keep ? undefined : refreshToken
|
|
758
|
-
);
|
|
776
|
+
if (refreshToken !== '') {
|
|
777
|
+
if (refreshToken != null) refreshToken = this.encrypt(refreshToken);
|
|
778
|
+
StorageUtils.setLocalData(this.headerTokenField, refreshToken);
|
|
759
779
|
}
|
|
760
|
-
|
|
761
780
|
// Reset tryLogin state
|
|
762
781
|
this._isTryingLogin = false;
|
|
763
782
|
|
|
@@ -835,6 +854,13 @@ export abstract class CoreApp<
|
|
|
835
854
|
});
|
|
836
855
|
}
|
|
837
856
|
|
|
857
|
+
/**
|
|
858
|
+
* Clear cached token
|
|
859
|
+
*/
|
|
860
|
+
clearCacheToken() {
|
|
861
|
+
StorageUtils.setLocalData(this.headerTokenField, null);
|
|
862
|
+
}
|
|
863
|
+
|
|
838
864
|
/**
|
|
839
865
|
* Decrypt message
|
|
840
866
|
* @param messageEncrypted Encrypted message
|
|
@@ -1136,19 +1162,16 @@ export abstract class CoreApp<
|
|
|
1136
1162
|
* @returns Cached token
|
|
1137
1163
|
*/
|
|
1138
1164
|
getCacheToken(): string | null {
|
|
1139
|
-
|
|
1165
|
+
const refreshToken = StorageUtils.getLocalData<string>(
|
|
1140
1166
|
this.headerTokenField,
|
|
1141
1167
|
''
|
|
1142
1168
|
);
|
|
1143
|
-
if (refreshToken === '')
|
|
1144
|
-
refreshToken = StorageUtils.getSessionData(
|
|
1145
|
-
this.headerTokenField,
|
|
1146
|
-
''
|
|
1147
|
-
);
|
|
1148
1169
|
|
|
1149
1170
|
if (refreshToken === '') return null;
|
|
1150
1171
|
|
|
1151
|
-
|
|
1172
|
+
const result = this.decrypt(refreshToken);
|
|
1173
|
+
if (result == undefined) return null;
|
|
1174
|
+
return result;
|
|
1152
1175
|
}
|
|
1153
1176
|
|
|
1154
1177
|
/**
|
|
@@ -1368,11 +1391,10 @@ export abstract class CoreApp<
|
|
|
1368
1391
|
* User login
|
|
1369
1392
|
* @param user User data
|
|
1370
1393
|
* @param refreshToken Refresh token
|
|
1371
|
-
* @param keep Keep in local storage or not
|
|
1372
1394
|
*/
|
|
1373
|
-
userLogin(user: IUserData, refreshToken: string
|
|
1395
|
+
userLogin(user: IUserData, refreshToken: string) {
|
|
1374
1396
|
this.userData = user;
|
|
1375
|
-
this.authorize(user.token, refreshToken
|
|
1397
|
+
this.authorize(user.token, refreshToken);
|
|
1376
1398
|
}
|
|
1377
1399
|
|
|
1378
1400
|
/**
|
|
@@ -1380,14 +1402,14 @@ export abstract class CoreApp<
|
|
|
1380
1402
|
* @param clearToken Clear refresh token or not
|
|
1381
1403
|
*/
|
|
1382
1404
|
userLogout(clearToken: boolean = true) {
|
|
1383
|
-
this.authorize(undefined,
|
|
1405
|
+
this.authorize(undefined, clearToken ? undefined : '');
|
|
1384
1406
|
}
|
|
1385
1407
|
|
|
1386
1408
|
/**
|
|
1387
1409
|
* User unauthorized
|
|
1388
1410
|
*/
|
|
1389
1411
|
userUnauthorized() {
|
|
1390
|
-
this.authorize(undefined, undefined
|
|
1412
|
+
this.authorize(undefined, undefined);
|
|
1391
1413
|
}
|
|
1392
1414
|
|
|
1393
1415
|
private lastWarning?: INotification<N, C>;
|