@etsoo/appscript 1.2.1 → 1.2.2

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.
@@ -431,6 +431,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
431
431
  */
432
432
  protected passphrase: string;
433
433
  private cachedRefreshToken?;
434
+ /**
435
+ * Get persisted fields
436
+ */
437
+ protected get persistedFields(): string[];
434
438
  /**
435
439
  * Protected constructor
436
440
  * @param settings Settings
@@ -112,6 +112,16 @@ class CoreApp {
112
112
  set authorized(value) {
113
113
  this._authorized = value;
114
114
  }
115
+ /**
116
+ * Get persisted fields
117
+ */
118
+ get persistedFields() {
119
+ return [
120
+ CoreApp.deviceIdField,
121
+ CoreApp.serversideDeviceIdField,
122
+ CoreApp.headerTokenField
123
+ ];
124
+ }
115
125
  /**
116
126
  * Restore settings from persisted source
117
127
  */
@@ -125,20 +135,16 @@ class CoreApp {
125
135
  }
126
136
  }
127
137
  // Restore
128
- this.storage.copy([
129
- CoreApp.deviceIdField,
130
- CoreApp.serversideDeviceIdField,
131
- CoreApp.headerTokenField
132
- ], true);
138
+ this.storage.copy(this.persistedFields, true);
133
139
  return true;
134
140
  }
135
141
  /**
136
142
  * Persist settings to source when application exit
137
143
  */
138
144
  persist() {
139
- this.storage.setPersistedData(CoreApp.deviceIdField, this.deviceId);
140
- this.storage.setPersistedData(CoreApp.serversideDeviceIdField, this.storage.getData(CoreApp.serversideDeviceIdField));
141
- this.storage.setPersistedData(CoreApp.headerTokenField, this.storage.getData(CoreApp.headerTokenField));
145
+ this.persistedFields.forEach((field) => {
146
+ this.storage.setPersistedData(field, this.storage.getData(field));
147
+ });
142
148
  }
143
149
  /**
144
150
  * Setup Api
@@ -386,17 +392,15 @@ class CoreApp {
386
392
  * Clear cache data
387
393
  */
388
394
  clearCacheData() {
389
- this.storage.setData(CoreApp.serversideDeviceIdField, undefined);
390
- this.storage.setData(CoreApp.deviceIdField, undefined);
395
+ this.clearCacheToken();
391
396
  this.storage.setData(CoreApp.devicePassphraseField, undefined);
392
- this.storage.setData(CoreApp.headerTokenField, undefined);
393
397
  }
394
398
  /**
395
399
  * Clear cached token
396
400
  */
397
401
  clearCacheToken() {
398
402
  this.cachedRefreshToken = undefined;
399
- this.storage.setData(CoreApp.headerTokenField, undefined);
403
+ this.storage.setPersistedData(CoreApp.headerTokenField, undefined);
400
404
  }
401
405
  /**
402
406
  * Decrypt message
@@ -431,6 +431,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
431
431
  */
432
432
  protected passphrase: string;
433
433
  private cachedRefreshToken?;
434
+ /**
435
+ * Get persisted fields
436
+ */
437
+ protected get persistedFields(): string[];
434
438
  /**
435
439
  * Protected constructor
436
440
  * @param settings Settings
@@ -109,6 +109,16 @@ export class CoreApp {
109
109
  set authorized(value) {
110
110
  this._authorized = value;
111
111
  }
112
+ /**
113
+ * Get persisted fields
114
+ */
115
+ get persistedFields() {
116
+ return [
117
+ CoreApp.deviceIdField,
118
+ CoreApp.serversideDeviceIdField,
119
+ CoreApp.headerTokenField
120
+ ];
121
+ }
112
122
  /**
113
123
  * Restore settings from persisted source
114
124
  */
@@ -122,20 +132,16 @@ export class CoreApp {
122
132
  }
123
133
  }
124
134
  // Restore
125
- this.storage.copy([
126
- CoreApp.deviceIdField,
127
- CoreApp.serversideDeviceIdField,
128
- CoreApp.headerTokenField
129
- ], true);
135
+ this.storage.copy(this.persistedFields, true);
130
136
  return true;
131
137
  }
132
138
  /**
133
139
  * Persist settings to source when application exit
134
140
  */
135
141
  persist() {
136
- this.storage.setPersistedData(CoreApp.deviceIdField, this.deviceId);
137
- this.storage.setPersistedData(CoreApp.serversideDeviceIdField, this.storage.getData(CoreApp.serversideDeviceIdField));
138
- this.storage.setPersistedData(CoreApp.headerTokenField, this.storage.getData(CoreApp.headerTokenField));
142
+ this.persistedFields.forEach((field) => {
143
+ this.storage.setPersistedData(field, this.storage.getData(field));
144
+ });
139
145
  }
140
146
  /**
141
147
  * Setup Api
@@ -383,17 +389,15 @@ export class CoreApp {
383
389
  * Clear cache data
384
390
  */
385
391
  clearCacheData() {
386
- this.storage.setData(CoreApp.serversideDeviceIdField, undefined);
387
- this.storage.setData(CoreApp.deviceIdField, undefined);
392
+ this.clearCacheToken();
388
393
  this.storage.setData(CoreApp.devicePassphraseField, undefined);
389
- this.storage.setData(CoreApp.headerTokenField, undefined);
390
394
  }
391
395
  /**
392
396
  * Clear cached token
393
397
  */
394
398
  clearCacheToken() {
395
399
  this.cachedRefreshToken = undefined;
396
- this.storage.setData(CoreApp.headerTokenField, undefined);
400
+ this.storage.setPersistedData(CoreApp.headerTokenField, undefined);
397
401
  }
398
402
  /**
399
403
  * Decrypt message
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -600,6 +600,17 @@ export abstract class CoreApp<
600
600
 
601
601
  private cachedRefreshToken?: string;
602
602
 
603
+ /**
604
+ * Get persisted fields
605
+ */
606
+ protected get persistedFields() {
607
+ return [
608
+ CoreApp.deviceIdField,
609
+ CoreApp.serversideDeviceIdField,
610
+ CoreApp.headerTokenField
611
+ ];
612
+ }
613
+
603
614
  /**
604
615
  * Protected constructor
605
616
  * @param settings Settings
@@ -657,14 +668,7 @@ export abstract class CoreApp<
657
668
  }
658
669
 
659
670
  // Restore
660
- this.storage.copy(
661
- [
662
- CoreApp.deviceIdField,
663
- CoreApp.serversideDeviceIdField,
664
- CoreApp.headerTokenField
665
- ],
666
- true
667
- );
671
+ this.storage.copy(this.persistedFields, true);
668
672
 
669
673
  return true;
670
674
  }
@@ -673,17 +677,9 @@ export abstract class CoreApp<
673
677
  * Persist settings to source when application exit
674
678
  */
675
679
  persist() {
676
- this.storage.setPersistedData(CoreApp.deviceIdField, this.deviceId);
677
-
678
- this.storage.setPersistedData(
679
- CoreApp.serversideDeviceIdField,
680
- this.storage.getData<string>(CoreApp.serversideDeviceIdField)
681
- );
682
-
683
- this.storage.setPersistedData(
684
- CoreApp.headerTokenField,
685
- this.storage.getData<string>(CoreApp.headerTokenField)
686
- );
680
+ this.persistedFields.forEach((field) => {
681
+ this.storage.setPersistedData(field, this.storage.getData(field));
682
+ });
687
683
  }
688
684
 
689
685
  /**
@@ -982,12 +978,8 @@ export abstract class CoreApp<
982
978
  * Clear cache data
983
979
  */
984
980
  clearCacheData() {
985
- this.storage.setData(CoreApp.serversideDeviceIdField, undefined);
986
-
987
- this.storage.setData(CoreApp.deviceIdField, undefined);
981
+ this.clearCacheToken();
988
982
  this.storage.setData(CoreApp.devicePassphraseField, undefined);
989
-
990
- this.storage.setData(CoreApp.headerTokenField, undefined);
991
983
  }
992
984
 
993
985
  /**
@@ -995,7 +987,7 @@ export abstract class CoreApp<
995
987
  */
996
988
  clearCacheToken() {
997
989
  this.cachedRefreshToken = undefined;
998
- this.storage.setData(CoreApp.headerTokenField, undefined);
990
+ this.storage.setPersistedData(CoreApp.headerTokenField, undefined);
999
991
  }
1000
992
 
1001
993
  /**