@etsoo/appscript 1.1.73 → 1.1.77

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.
@@ -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, keep?: boolean): void;
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,7 +302,7 @@ 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
305
+ * @param keep Keep login or not
299
306
  */
300
307
  userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
301
308
  /**
@@ -349,6 +356,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
349
356
  * Country or region, like CN
350
357
  */
351
358
  get region(): string;
359
+ private _deviceId;
360
+ /**
361
+ * Country or region, like CN
362
+ */
363
+ get deviceId(): string;
364
+ protected set deviceId(value: string);
352
365
  /**
353
366
  * Label delegate
354
367
  */
@@ -389,14 +402,11 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
389
402
  * Device id field name
390
403
  */
391
404
  protected deviceIdField: string;
392
- /**
393
- * Device id
394
- */
395
- protected deviceId: string;
396
405
  /**
397
406
  * Passphrase for encryption
398
407
  */
399
408
  protected passphrase: string;
409
+ private cachedRefreshToken?;
400
410
  /**
401
411
  * Protected constructor
402
412
  * @param settings Settings
@@ -432,9 +442,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
432
442
  * Authorize
433
443
  * @param token New token
434
444
  * @param refreshToken Refresh token
435
- * @param keep Keep in local storage or not
436
445
  */
437
- authorize(token?: string, refreshToken?: string, keep?: boolean): void;
446
+ authorize(token?: string, refreshToken?: string): void;
438
447
  /**
439
448
  * Change country or region
440
449
  * @param regionId New country or region
@@ -445,6 +454,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
445
454
  * @param culture New culture definition
446
455
  */
447
456
  changeCulture(culture: DataTypes.CultureDefinition): void;
457
+ /**
458
+ * Clear cached token
459
+ */
460
+ clearCacheToken(): void;
448
461
  /**
449
462
  * Decrypt message
450
463
  * @param messageEncrypted Encrypted message
@@ -638,7 +651,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
638
651
  * User login
639
652
  * @param user User data
640
653
  * @param refreshToken Refresh token
641
- * @param keep Keep in local storage or not
654
+ * @param keep Keep login or not
642
655
  */
643
656
  userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
644
657
  /**
@@ -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
  */
@@ -187,12 +197,21 @@ class CoreApp {
187
197
  const fields = this.initCallUpdateFields();
188
198
  for (const field of fields) {
189
199
  const currentValue = shared_1.StorageUtils.getLocalData(field, '');
190
- if (currentValue === '' || currentValue.indexOf('+') === -1)
200
+ if (currentValue === '')
191
201
  continue;
192
- const newValueSource = this.decryptEnhanced(currentValue, prev, 12);
193
- if (newValueSource == null)
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 === '')
194
211
  continue;
195
- const newValue = this.encryptEnhanced(newValueSource);
212
+ const newValue = enhanced
213
+ ? this.encryptEnhanced(newValueSource)
214
+ : this.encrypt(newValueSource);
196
215
  shared_1.StorageUtils.setLocalData(field, newValue);
197
216
  }
198
217
  }
@@ -202,7 +221,7 @@ class CoreApp {
202
221
  * @returns Fields
203
222
  */
204
223
  initCallUpdateFields() {
205
- return [];
224
+ return [this.headerTokenField];
206
225
  }
207
226
  /**
208
227
  * Alert action result
@@ -216,25 +235,27 @@ class CoreApp {
216
235
  * Authorize
217
236
  * @param token New token
218
237
  * @param refreshToken Refresh token
219
- * @param keep Keep in local storage or not
220
238
  */
221
- authorize(token, refreshToken, keep) {
239
+ authorize(token, refreshToken) {
222
240
  // State, when token is null, means logout
223
241
  this.authorized = token != null;
224
242
  // Token
225
243
  this.api.authorize(this.settings.authScheme, token);
226
244
  // Cover the current value
227
- if (keep != null) {
228
- shared_1.StorageUtils.setLocalData(this.headerTokenField, keep ? refreshToken : undefined);
229
- shared_1.StorageUtils.setSessionData(this.headerTokenField, keep ? undefined : refreshToken);
245
+ if (refreshToken !== '') {
246
+ if (refreshToken != null)
247
+ refreshToken = this.encrypt(refreshToken);
248
+ shared_1.StorageUtils.setLocalData(this.headerTokenField, refreshToken);
230
249
  }
231
250
  // Reset tryLogin state
232
251
  this._isTryingLogin = false;
233
252
  // Token countdown
234
253
  if (this.authorized)
235
254
  this.refreshCountdown(this.userData.seconds);
236
- else
255
+ else {
256
+ this.cachedRefreshToken = undefined;
237
257
  this.refreshCountdownClear();
258
+ }
238
259
  }
239
260
  /**
240
261
  * Change country or region
@@ -292,6 +313,13 @@ class CoreApp {
292
313
  region.name = AddressUtils_1.AddressUtils.getRegionLabel(id, this.labelDelegate);
293
314
  });
294
315
  }
316
+ /**
317
+ * Clear cached token
318
+ */
319
+ clearCacheToken() {
320
+ this.cachedRefreshToken = undefined;
321
+ shared_1.StorageUtils.setLocalData(this.headerTokenField, undefined);
322
+ }
295
323
  /**
296
324
  * Decrypt message
297
325
  * @param messageEncrypted Encrypted message
@@ -535,12 +563,16 @@ class CoreApp {
535
563
  * @returns Cached token
536
564
  */
537
565
  getCacheToken() {
538
- let refreshToken = shared_1.StorageUtils.getLocalData(this.headerTokenField, '');
539
- if (refreshToken === '')
540
- refreshToken = shared_1.StorageUtils.getSessionData(this.headerTokenField, '');
566
+ // Temp refresh token
567
+ if (this.cachedRefreshToken)
568
+ return this.cachedRefreshToken;
569
+ const refreshToken = shared_1.StorageUtils.getLocalData(this.headerTokenField, '');
541
570
  if (refreshToken === '')
542
571
  return null;
543
- return refreshToken;
572
+ const result = this.decrypt(refreshToken);
573
+ if (result == undefined)
574
+ return null;
575
+ return result;
544
576
  }
545
577
  /**
546
578
  * Get all regions
@@ -738,24 +770,30 @@ class CoreApp {
738
770
  * User login
739
771
  * @param user User data
740
772
  * @param refreshToken Refresh token
741
- * @param keep Keep in local storage or not
773
+ * @param keep Keep login or not
742
774
  */
743
- userLogin(user, refreshToken, keep = false) {
775
+ userLogin(user, refreshToken, keep) {
744
776
  this.userData = user;
745
- this.authorize(user.token, refreshToken, keep);
777
+ if (keep) {
778
+ this.authorize(user.token, refreshToken);
779
+ }
780
+ else {
781
+ this.cachedRefreshToken = refreshToken;
782
+ this.authorize(user.token, undefined);
783
+ }
746
784
  }
747
785
  /**
748
786
  * User logout
749
787
  * @param clearToken Clear refresh token or not
750
788
  */
751
789
  userLogout(clearToken = true) {
752
- this.authorize(undefined, undefined, clearToken ? false : undefined);
790
+ this.authorize(undefined, clearToken ? undefined : '');
753
791
  }
754
792
  /**
755
793
  * User unauthorized
756
794
  */
757
795
  userUnauthorized() {
758
- this.authorize(undefined, undefined, undefined);
796
+ this.authorize(undefined, undefined);
759
797
  }
760
798
  /**
761
799
  * Show warning message
@@ -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, keep?: boolean): void;
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,7 +302,7 @@ 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
305
+ * @param keep Keep login or not
299
306
  */
300
307
  userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
301
308
  /**
@@ -349,6 +356,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
349
356
  * Country or region, like CN
350
357
  */
351
358
  get region(): string;
359
+ private _deviceId;
360
+ /**
361
+ * Country or region, like CN
362
+ */
363
+ get deviceId(): string;
364
+ protected set deviceId(value: string);
352
365
  /**
353
366
  * Label delegate
354
367
  */
@@ -389,14 +402,11 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
389
402
  * Device id field name
390
403
  */
391
404
  protected deviceIdField: string;
392
- /**
393
- * Device id
394
- */
395
- protected deviceId: string;
396
405
  /**
397
406
  * Passphrase for encryption
398
407
  */
399
408
  protected passphrase: string;
409
+ private cachedRefreshToken?;
400
410
  /**
401
411
  * Protected constructor
402
412
  * @param settings Settings
@@ -432,9 +442,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
432
442
  * Authorize
433
443
  * @param token New token
434
444
  * @param refreshToken Refresh token
435
- * @param keep Keep in local storage or not
436
445
  */
437
- authorize(token?: string, refreshToken?: string, keep?: boolean): void;
446
+ authorize(token?: string, refreshToken?: string): void;
438
447
  /**
439
448
  * Change country or region
440
449
  * @param regionId New country or region
@@ -445,6 +454,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
445
454
  * @param culture New culture definition
446
455
  */
447
456
  changeCulture(culture: DataTypes.CultureDefinition): void;
457
+ /**
458
+ * Clear cached token
459
+ */
460
+ clearCacheToken(): void;
448
461
  /**
449
462
  * Decrypt message
450
463
  * @param messageEncrypted Encrypted message
@@ -638,7 +651,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
638
651
  * User login
639
652
  * @param user User data
640
653
  * @param refreshToken Refresh token
641
- * @param keep Keep in local storage or not
654
+ * @param keep Keep login or not
642
655
  */
643
656
  userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
644
657
  /**
@@ -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
  */
@@ -184,12 +194,21 @@ export class CoreApp {
184
194
  const fields = this.initCallUpdateFields();
185
195
  for (const field of fields) {
186
196
  const currentValue = StorageUtils.getLocalData(field, '');
187
- if (currentValue === '' || currentValue.indexOf('+') === -1)
197
+ if (currentValue === '')
188
198
  continue;
189
- const newValueSource = this.decryptEnhanced(currentValue, prev, 12);
190
- if (newValueSource == null)
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 === '')
191
208
  continue;
192
- const newValue = this.encryptEnhanced(newValueSource);
209
+ const newValue = enhanced
210
+ ? this.encryptEnhanced(newValueSource)
211
+ : this.encrypt(newValueSource);
193
212
  StorageUtils.setLocalData(field, newValue);
194
213
  }
195
214
  }
@@ -199,7 +218,7 @@ export class CoreApp {
199
218
  * @returns Fields
200
219
  */
201
220
  initCallUpdateFields() {
202
- return [];
221
+ return [this.headerTokenField];
203
222
  }
204
223
  /**
205
224
  * Alert action result
@@ -213,25 +232,27 @@ export class CoreApp {
213
232
  * Authorize
214
233
  * @param token New token
215
234
  * @param refreshToken Refresh token
216
- * @param keep Keep in local storage or not
217
235
  */
218
- authorize(token, refreshToken, keep) {
236
+ authorize(token, refreshToken) {
219
237
  // State, when token is null, means logout
220
238
  this.authorized = token != null;
221
239
  // Token
222
240
  this.api.authorize(this.settings.authScheme, token);
223
241
  // Cover the current value
224
- if (keep != null) {
225
- StorageUtils.setLocalData(this.headerTokenField, keep ? refreshToken : undefined);
226
- StorageUtils.setSessionData(this.headerTokenField, keep ? undefined : refreshToken);
242
+ if (refreshToken !== '') {
243
+ if (refreshToken != null)
244
+ refreshToken = this.encrypt(refreshToken);
245
+ StorageUtils.setLocalData(this.headerTokenField, refreshToken);
227
246
  }
228
247
  // Reset tryLogin state
229
248
  this._isTryingLogin = false;
230
249
  // Token countdown
231
250
  if (this.authorized)
232
251
  this.refreshCountdown(this.userData.seconds);
233
- else
252
+ else {
253
+ this.cachedRefreshToken = undefined;
234
254
  this.refreshCountdownClear();
255
+ }
235
256
  }
236
257
  /**
237
258
  * Change country or region
@@ -289,6 +310,13 @@ export class CoreApp {
289
310
  region.name = AddressUtils.getRegionLabel(id, this.labelDelegate);
290
311
  });
291
312
  }
313
+ /**
314
+ * Clear cached token
315
+ */
316
+ clearCacheToken() {
317
+ this.cachedRefreshToken = undefined;
318
+ StorageUtils.setLocalData(this.headerTokenField, undefined);
319
+ }
292
320
  /**
293
321
  * Decrypt message
294
322
  * @param messageEncrypted Encrypted message
@@ -532,12 +560,16 @@ export class CoreApp {
532
560
  * @returns Cached token
533
561
  */
534
562
  getCacheToken() {
535
- let refreshToken = StorageUtils.getLocalData(this.headerTokenField, '');
536
- if (refreshToken === '')
537
- refreshToken = StorageUtils.getSessionData(this.headerTokenField, '');
563
+ // Temp refresh token
564
+ if (this.cachedRefreshToken)
565
+ return this.cachedRefreshToken;
566
+ const refreshToken = StorageUtils.getLocalData(this.headerTokenField, '');
538
567
  if (refreshToken === '')
539
568
  return null;
540
- return refreshToken;
569
+ const result = this.decrypt(refreshToken);
570
+ if (result == undefined)
571
+ return null;
572
+ return result;
541
573
  }
542
574
  /**
543
575
  * Get all regions
@@ -735,24 +767,30 @@ export class CoreApp {
735
767
  * User login
736
768
  * @param user User data
737
769
  * @param refreshToken Refresh token
738
- * @param keep Keep in local storage or not
770
+ * @param keep Keep login or not
739
771
  */
740
- userLogin(user, refreshToken, keep = false) {
772
+ userLogin(user, refreshToken, keep) {
741
773
  this.userData = user;
742
- this.authorize(user.token, refreshToken, keep);
774
+ if (keep) {
775
+ this.authorize(user.token, refreshToken);
776
+ }
777
+ else {
778
+ this.cachedRefreshToken = refreshToken;
779
+ this.authorize(user.token, undefined);
780
+ }
743
781
  }
744
782
  /**
745
783
  * User logout
746
784
  * @param clearToken Clear refresh token or not
747
785
  */
748
786
  userLogout(clearToken = true) {
749
- this.authorize(undefined, undefined, clearToken ? false : undefined);
787
+ this.authorize(undefined, clearToken ? undefined : '');
750
788
  }
751
789
  /**
752
790
  * User unauthorized
753
791
  */
754
792
  userUnauthorized() {
755
- this.authorize(undefined, undefined, undefined);
793
+ this.authorize(undefined, undefined);
756
794
  }
757
795
  /**
758
796
  * Show warning message
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.1.73",
3
+ "version": "1.1.77",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -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, keep?: boolean): void;
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,7 +411,7 @@ 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
414
+ * @param keep Keep login or not
406
415
  */
407
416
  userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
408
417
 
@@ -478,6 +487,17 @@ export abstract class CoreApp<
478
487
  return this._region;
479
488
  }
480
489
 
490
+ private _deviceId: string = '***';
491
+ /**
492
+ * Country or region, like CN
493
+ */
494
+ get deviceId() {
495
+ return this._deviceId;
496
+ }
497
+ protected set deviceId(value: string) {
498
+ this._deviceId = value;
499
+ }
500
+
481
501
  /**
482
502
  * Label delegate
483
503
  */
@@ -537,16 +557,13 @@ export abstract class CoreApp<
537
557
  */
538
558
  protected deviceIdField: string = 'SmartERPDeviceId';
539
559
 
540
- /**
541
- * Device id
542
- */
543
- protected deviceId: string;
544
-
545
560
  /**
546
561
  * Passphrase for encryption
547
562
  */
548
563
  protected passphrase: string = '***';
549
564
 
565
+ private cachedRefreshToken?: string;
566
+
550
567
  /**
551
568
  * Protected constructor
552
569
  * @param settings Settings
@@ -703,17 +720,27 @@ export abstract class CoreApp<
703
720
  field,
704
721
  ''
705
722
  );
706
- if (currentValue === '' || currentValue.indexOf('+') === -1)
707
- continue;
723
+ if (currentValue === '') continue;
708
724
 
709
- const newValueSource = this.decryptEnhanced(
710
- currentValue,
711
- prev,
712
- 12
713
- );
714
- if (newValueSource == null) continue;
725
+ const enhanced = currentValue.indexOf('!') >= 8;
726
+ let newValueSource = null;
727
+
728
+ if (enhanced) {
729
+ newValueSource = this.decryptEnhanced(
730
+ currentValue,
731
+ prev,
732
+ 12
733
+ );
734
+ } else {
735
+ newValueSource = this.decrypt(currentValue, prev);
736
+ }
737
+
738
+ if (newValueSource == null || newValueSource === '') continue;
739
+
740
+ const newValue = enhanced
741
+ ? this.encryptEnhanced(newValueSource)
742
+ : this.encrypt(newValueSource);
715
743
 
716
- const newValue = this.encryptEnhanced(newValueSource);
717
744
  StorageUtils.setLocalData(field, newValue);
718
745
  }
719
746
  }
@@ -724,7 +751,7 @@ export abstract class CoreApp<
724
751
  * @returns Fields
725
752
  */
726
753
  protected initCallUpdateFields(): string[] {
727
- return [];
754
+ return [this.headerTokenField];
728
755
  }
729
756
 
730
757
  /**
@@ -740,9 +767,8 @@ export abstract class CoreApp<
740
767
  * Authorize
741
768
  * @param token New token
742
769
  * @param refreshToken Refresh token
743
- * @param keep Keep in local storage or not
744
770
  */
745
- authorize(token?: string, refreshToken?: string, keep?: boolean) {
771
+ authorize(token?: string, refreshToken?: string) {
746
772
  // State, when token is null, means logout
747
773
  this.authorized = token != null;
748
774
 
@@ -750,15 +776,9 @@ export abstract class CoreApp<
750
776
  this.api.authorize(this.settings.authScheme, token);
751
777
 
752
778
  // Cover the current value
753
- if (keep != null) {
754
- StorageUtils.setLocalData(
755
- this.headerTokenField,
756
- keep ? refreshToken : undefined
757
- );
758
- StorageUtils.setSessionData(
759
- this.headerTokenField,
760
- keep ? undefined : refreshToken
761
- );
779
+ if (refreshToken !== '') {
780
+ if (refreshToken != null) refreshToken = this.encrypt(refreshToken);
781
+ StorageUtils.setLocalData(this.headerTokenField, refreshToken);
762
782
  }
763
783
 
764
784
  // Reset tryLogin state
@@ -766,7 +786,10 @@ export abstract class CoreApp<
766
786
 
767
787
  // Token countdown
768
788
  if (this.authorized) this.refreshCountdown(this.userData!.seconds);
769
- else this.refreshCountdownClear();
789
+ else {
790
+ this.cachedRefreshToken = undefined;
791
+ this.refreshCountdownClear();
792
+ }
770
793
  }
771
794
 
772
795
  /**
@@ -838,6 +861,14 @@ export abstract class CoreApp<
838
861
  });
839
862
  }
840
863
 
864
+ /**
865
+ * Clear cached token
866
+ */
867
+ clearCacheToken() {
868
+ this.cachedRefreshToken = undefined;
869
+ StorageUtils.setLocalData(this.headerTokenField, undefined);
870
+ }
871
+
841
872
  /**
842
873
  * Decrypt message
843
874
  * @param messageEncrypted Encrypted message
@@ -1139,19 +1170,19 @@ export abstract class CoreApp<
1139
1170
  * @returns Cached token
1140
1171
  */
1141
1172
  getCacheToken(): string | null {
1142
- let refreshToken = StorageUtils.getLocalData<string>(
1173
+ // Temp refresh token
1174
+ if (this.cachedRefreshToken) return this.cachedRefreshToken;
1175
+
1176
+ const refreshToken = StorageUtils.getLocalData<string>(
1143
1177
  this.headerTokenField,
1144
1178
  ''
1145
1179
  );
1146
- if (refreshToken === '')
1147
- refreshToken = StorageUtils.getSessionData(
1148
- this.headerTokenField,
1149
- ''
1150
- );
1151
1180
 
1152
1181
  if (refreshToken === '') return null;
1153
1182
 
1154
- return refreshToken;
1183
+ const result = this.decrypt(refreshToken);
1184
+ if (result == undefined) return null;
1185
+ return result;
1155
1186
  }
1156
1187
 
1157
1188
  /**
@@ -1371,11 +1402,17 @@ export abstract class CoreApp<
1371
1402
  * User login
1372
1403
  * @param user User data
1373
1404
  * @param refreshToken Refresh token
1374
- * @param keep Keep in local storage or not
1405
+ * @param keep Keep login or not
1375
1406
  */
1376
- userLogin(user: IUserData, refreshToken: string, keep: boolean = false) {
1407
+ userLogin(user: IUserData, refreshToken: string, keep?: boolean) {
1377
1408
  this.userData = user;
1378
- this.authorize(user.token, refreshToken, keep);
1409
+
1410
+ if (keep) {
1411
+ this.authorize(user.token, refreshToken);
1412
+ } else {
1413
+ this.cachedRefreshToken = refreshToken;
1414
+ this.authorize(user.token, undefined);
1415
+ }
1379
1416
  }
1380
1417
 
1381
1418
  /**
@@ -1383,14 +1420,14 @@ export abstract class CoreApp<
1383
1420
  * @param clearToken Clear refresh token or not
1384
1421
  */
1385
1422
  userLogout(clearToken: boolean = true) {
1386
- this.authorize(undefined, undefined, clearToken ? false : undefined);
1423
+ this.authorize(undefined, clearToken ? undefined : '');
1387
1424
  }
1388
1425
 
1389
1426
  /**
1390
1427
  * User unauthorized
1391
1428
  */
1392
1429
  userUnauthorized() {
1393
- this.authorize(undefined, undefined, undefined);
1430
+ this.authorize(undefined, undefined);
1394
1431
  }
1395
1432
 
1396
1433
  private lastWarning?: INotification<N, C>;