@etsoo/appscript 1.1.87 → 1.1.88

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.
@@ -422,11 +422,15 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
422
422
  /**
423
423
  * Device id field name
424
424
  */
425
- protected readonly deviceIdField: string;
425
+ private readonly deviceIdField;
426
+ /**
427
+ * Device passphrase field name
428
+ */
429
+ private readonly devicePassphraseField;
426
430
  /**
427
431
  * Device id update time field name
428
432
  */
429
- protected readonly deviceIdUpdateTimeField: string;
433
+ private readonly deviceIdUpdateTimeField;
430
434
  /**
431
435
  * Init call Api URL
432
436
  */
@@ -445,6 +449,11 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
445
449
  */
446
450
  protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, name: string);
447
451
  protected setApi(api: IApi): void;
452
+ /**
453
+ * Setup device
454
+ * @returns Device id
455
+ */
456
+ protected setupDevice(): string;
448
457
  /**
449
458
  * Api init call
450
459
  * @param data Data
@@ -43,6 +43,10 @@ class CoreApp {
43
43
  * Device id field name
44
44
  */
45
45
  this.deviceIdField = 'SmartERPDeviceId';
46
+ /**
47
+ * Device passphrase field name
48
+ */
49
+ this.devicePassphraseField = 'SmartERPDevicePassphrase';
46
50
  /**
47
51
  * Device id update time field name
48
52
  */
@@ -59,7 +63,7 @@ class CoreApp {
59
63
  this.api = api;
60
64
  this.notifier = notifier;
61
65
  this.name = name;
62
- this.deviceId = shared_1.StorageUtils.getLocalData(this.deviceIdField, '');
66
+ this.deviceId = this.setupDevice();
63
67
  this.setApi(api);
64
68
  const { currentCulture, currentRegion } = settings;
65
69
  this.changeCulture(currentCulture);
@@ -157,6 +161,25 @@ class CoreApp {
157
161
  }
158
162
  };
159
163
  }
164
+ /**
165
+ * Setup device
166
+ * @returns Device id
167
+ */
168
+ setupDevice() {
169
+ const deviceId = shared_1.StorageUtils.getLocalData(this.deviceIdField);
170
+ if (deviceId != null && deviceId !== '') {
171
+ const passphraseEncrypted = shared_1.StorageUtils.getLocalData(this.devicePassphraseField);
172
+ if (passphraseEncrypted != null && passphraseEncrypted !== '') {
173
+ const timestamp = this.getDeviceUpdateTime();
174
+ if (timestamp > 0) {
175
+ const passphraseDecrypted = this.decrypt(passphraseEncrypted, timestamp.toString());
176
+ if (passphraseDecrypted != null)
177
+ this.passphrase = passphraseDecrypted;
178
+ }
179
+ }
180
+ }
181
+ return deviceId !== null && deviceId !== void 0 ? deviceId : '';
182
+ }
160
183
  /**
161
184
  * Api init call
162
185
  * @param data Data
@@ -248,6 +271,7 @@ class CoreApp {
248
271
  // Update device id and cache it
249
272
  this.deviceId = data.deviceId;
250
273
  shared_1.StorageUtils.setLocalData(this.deviceIdField, this.deviceId);
274
+ shared_1.StorageUtils.setLocalData(this.devicePassphraseField, data.passphrase);
251
275
  shared_1.StorageUtils.setLocalData(this.deviceIdUpdateTimeField, timestamp);
252
276
  // Current passphrase
253
277
  this.passphrase = passphrase;
@@ -380,6 +404,7 @@ class CoreApp {
380
404
  clearCacheData() {
381
405
  shared_1.StorageUtils.setLocalData(this.serversideDeviceIdField, undefined);
382
406
  shared_1.StorageUtils.setLocalData(this.deviceIdField, undefined);
407
+ shared_1.StorageUtils.setLocalData(this.devicePassphraseField, undefined);
383
408
  shared_1.StorageUtils.setLocalData(this.deviceIdUpdateTimeField, undefined);
384
409
  shared_1.StorageUtils.setLocalData(this.headerTokenField, undefined);
385
410
  }
@@ -854,7 +879,7 @@ class CoreApp {
854
879
  this.authorize(user.token, refreshToken);
855
880
  }
856
881
  else {
857
- this.cachedRefreshToken = refreshToken;
882
+ this.cachedRefreshToken = this.encrypt(refreshToken);
858
883
  this.authorize(user.token, undefined);
859
884
  }
860
885
  }
@@ -422,11 +422,15 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
422
422
  /**
423
423
  * Device id field name
424
424
  */
425
- protected readonly deviceIdField: string;
425
+ private readonly deviceIdField;
426
+ /**
427
+ * Device passphrase field name
428
+ */
429
+ private readonly devicePassphraseField;
426
430
  /**
427
431
  * Device id update time field name
428
432
  */
429
- protected readonly deviceIdUpdateTimeField: string;
433
+ private readonly deviceIdUpdateTimeField;
430
434
  /**
431
435
  * Init call Api URL
432
436
  */
@@ -445,6 +449,11 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
445
449
  */
446
450
  protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, name: string);
447
451
  protected setApi(api: IApi): void;
452
+ /**
453
+ * Setup device
454
+ * @returns Device id
455
+ */
456
+ protected setupDevice(): string;
448
457
  /**
449
458
  * Api init call
450
459
  * @param data Data
@@ -40,6 +40,10 @@ export class CoreApp {
40
40
  * Device id field name
41
41
  */
42
42
  this.deviceIdField = 'SmartERPDeviceId';
43
+ /**
44
+ * Device passphrase field name
45
+ */
46
+ this.devicePassphraseField = 'SmartERPDevicePassphrase';
43
47
  /**
44
48
  * Device id update time field name
45
49
  */
@@ -56,7 +60,7 @@ export class CoreApp {
56
60
  this.api = api;
57
61
  this.notifier = notifier;
58
62
  this.name = name;
59
- this.deviceId = StorageUtils.getLocalData(this.deviceIdField, '');
63
+ this.deviceId = this.setupDevice();
60
64
  this.setApi(api);
61
65
  const { currentCulture, currentRegion } = settings;
62
66
  this.changeCulture(currentCulture);
@@ -154,6 +158,25 @@ export class CoreApp {
154
158
  }
155
159
  };
156
160
  }
161
+ /**
162
+ * Setup device
163
+ * @returns Device id
164
+ */
165
+ setupDevice() {
166
+ const deviceId = StorageUtils.getLocalData(this.deviceIdField);
167
+ if (deviceId != null && deviceId !== '') {
168
+ const passphraseEncrypted = StorageUtils.getLocalData(this.devicePassphraseField);
169
+ if (passphraseEncrypted != null && passphraseEncrypted !== '') {
170
+ const timestamp = this.getDeviceUpdateTime();
171
+ if (timestamp > 0) {
172
+ const passphraseDecrypted = this.decrypt(passphraseEncrypted, timestamp.toString());
173
+ if (passphraseDecrypted != null)
174
+ this.passphrase = passphraseDecrypted;
175
+ }
176
+ }
177
+ }
178
+ return deviceId !== null && deviceId !== void 0 ? deviceId : '';
179
+ }
157
180
  /**
158
181
  * Api init call
159
182
  * @param data Data
@@ -245,6 +268,7 @@ export class CoreApp {
245
268
  // Update device id and cache it
246
269
  this.deviceId = data.deviceId;
247
270
  StorageUtils.setLocalData(this.deviceIdField, this.deviceId);
271
+ StorageUtils.setLocalData(this.devicePassphraseField, data.passphrase);
248
272
  StorageUtils.setLocalData(this.deviceIdUpdateTimeField, timestamp);
249
273
  // Current passphrase
250
274
  this.passphrase = passphrase;
@@ -377,6 +401,7 @@ export class CoreApp {
377
401
  clearCacheData() {
378
402
  StorageUtils.setLocalData(this.serversideDeviceIdField, undefined);
379
403
  StorageUtils.setLocalData(this.deviceIdField, undefined);
404
+ StorageUtils.setLocalData(this.devicePassphraseField, undefined);
380
405
  StorageUtils.setLocalData(this.deviceIdUpdateTimeField, undefined);
381
406
  StorageUtils.setLocalData(this.headerTokenField, undefined);
382
407
  }
@@ -851,7 +876,7 @@ export class CoreApp {
851
876
  this.authorize(user.token, refreshToken);
852
877
  }
853
878
  else {
854
- this.cachedRefreshToken = refreshToken;
879
+ this.cachedRefreshToken = this.encrypt(refreshToken);
855
880
  this.authorize(user.token, undefined);
856
881
  }
857
882
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.1.87",
3
+ "version": "1.1.88",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -589,12 +589,17 @@ export abstract class CoreApp<
589
589
  /**
590
590
  * Device id field name
591
591
  */
592
- protected readonly deviceIdField: string = 'SmartERPDeviceId';
592
+ private readonly deviceIdField: string = 'SmartERPDeviceId';
593
+
594
+ /**
595
+ * Device passphrase field name
596
+ */
597
+ private readonly devicePassphraseField: string = 'SmartERPDevicePassphrase';
593
598
 
594
599
  /**
595
600
  * Device id update time field name
596
601
  */
597
- protected readonly deviceIdUpdateTimeField: string =
602
+ private readonly deviceIdUpdateTimeField: string =
598
603
  'SmartERPDeviceIdUpdateTime';
599
604
 
600
605
  /**
@@ -627,10 +632,7 @@ export abstract class CoreApp<
627
632
  this.notifier = notifier;
628
633
  this.name = name;
629
634
 
630
- this.deviceId = StorageUtils.getLocalData<string>(
631
- this.deviceIdField,
632
- ''
633
- );
635
+ this.deviceId = this.setupDevice();
634
636
 
635
637
  this.setApi(api);
636
638
 
@@ -676,6 +678,33 @@ export abstract class CoreApp<
676
678
  };
677
679
  }
678
680
 
681
+ /**
682
+ * Setup device
683
+ * @returns Device id
684
+ */
685
+ protected setupDevice() {
686
+ const deviceId = StorageUtils.getLocalData<string>(this.deviceIdField);
687
+
688
+ if (deviceId != null && deviceId !== '') {
689
+ const passphraseEncrypted = StorageUtils.getLocalData<string>(
690
+ this.devicePassphraseField
691
+ );
692
+ if (passphraseEncrypted != null && passphraseEncrypted !== '') {
693
+ const timestamp = this.getDeviceUpdateTime();
694
+ if (timestamp > 0) {
695
+ const passphraseDecrypted = this.decrypt(
696
+ passphraseEncrypted,
697
+ timestamp.toString()
698
+ );
699
+ if (passphraseDecrypted != null)
700
+ this.passphrase = passphraseDecrypted;
701
+ }
702
+ }
703
+ }
704
+
705
+ return deviceId ?? '';
706
+ }
707
+
679
708
  /**
680
709
  * Api init call
681
710
  * @param data Data
@@ -781,6 +810,7 @@ export abstract class CoreApp<
781
810
  // Update device id and cache it
782
811
  this.deviceId = data.deviceId;
783
812
  StorageUtils.setLocalData(this.deviceIdField, this.deviceId);
813
+ StorageUtils.setLocalData(this.devicePassphraseField, data.passphrase);
784
814
  StorageUtils.setLocalData(this.deviceIdUpdateTimeField, timestamp);
785
815
 
786
816
  // Current passphrase
@@ -945,6 +975,7 @@ export abstract class CoreApp<
945
975
  StorageUtils.setLocalData(this.serversideDeviceIdField, undefined);
946
976
 
947
977
  StorageUtils.setLocalData(this.deviceIdField, undefined);
978
+ StorageUtils.setLocalData(this.devicePassphraseField, undefined);
948
979
  StorageUtils.setLocalData(this.deviceIdUpdateTimeField, undefined);
949
980
 
950
981
  StorageUtils.setLocalData(this.headerTokenField, undefined);
@@ -1506,7 +1537,7 @@ export abstract class CoreApp<
1506
1537
  if (keep) {
1507
1538
  this.authorize(user.token, refreshToken);
1508
1539
  } else {
1509
- this.cachedRefreshToken = refreshToken;
1540
+ this.cachedRefreshToken = this.encrypt(refreshToken);
1510
1541
  this.authorize(user.token, undefined);
1511
1542
  }
1512
1543
  }