@etsoo/appscript 1.2.7 → 1.2.8

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.
@@ -445,6 +445,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
445
445
  */
446
446
  protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, storage: IStorage, name: string);
447
447
  private getDeviceId;
448
+ private resetKeys;
448
449
  /**
449
450
  * Restore settings from persisted source
450
451
  */
@@ -126,42 +126,52 @@ class CoreApp {
126
126
  getDeviceId() {
127
127
  return this.deviceId.substring(0, 15);
128
128
  }
129
+ resetKeys() {
130
+ this.storage.clear([
131
+ CoreApp.devicePassphraseField,
132
+ CoreApp.headerTokenField,
133
+ CoreApp.serversideDeviceIdField
134
+ ], false);
135
+ this.passphrase = '';
136
+ }
129
137
  /**
130
138
  * Restore settings from persisted source
131
139
  */
132
140
  restore() {
141
+ // Devices
142
+ const devices = this.storage.getPersistedData(CoreApp.devicesField, []);
133
143
  // Current device id, '' means new, or reload (not included) or duplicate (included)
134
- if (this.deviceId) {
135
- // Devices
136
- const devices = this.storage.getPersistedData(CoreApp.devicesField, []);
137
- // Exists in the list?
144
+ if (this.deviceId === '') {
145
+ // First vist, restore
146
+ this.storage.copyFrom(this.persistedFields, true);
147
+ // Reset device id
148
+ this._deviceId = this.storage.getData(CoreApp.deviceIdField, '');
149
+ }
150
+ else {
138
151
  const d = this.getDeviceId();
139
- if (!devices.includes(d)) {
140
- const passphraseEncrypted = this.storage.getData(CoreApp.devicePassphraseField);
141
- if (passphraseEncrypted) {
142
- const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
143
- if (passphraseDecrypted != null) {
144
- this.passphrase = passphraseDecrypted;
145
- devices.push(d);
146
- this.storage.setPersistedData(CoreApp.devicesField, devices);
147
- return false;
148
- }
149
- }
150
- }
151
- else {
152
+ if (devices.includes(d)) {
152
153
  // Duplicate tab, session data copied
153
154
  // Remove the token, deviceId, and passphrase
154
- this.storage.clear([
155
- CoreApp.devicePassphraseField,
156
- CoreApp.headerTokenField,
157
- CoreApp.serversideDeviceIdField
158
- ], false);
159
- this.passphrase = '';
155
+ this.resetKeys();
156
+ return false;
160
157
  }
161
158
  }
162
- // Restore
163
- this.storage.copyFrom(this.persistedFields, true);
164
- return true;
159
+ const passphraseEncrypted = this.storage.getData(CoreApp.devicePassphraseField);
160
+ if (passphraseEncrypted) {
161
+ const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
162
+ if (passphraseDecrypted != null) {
163
+ this.passphrase = passphraseDecrypted;
164
+ const d = this.getDeviceId();
165
+ if (!devices.includes(d)) {
166
+ devices.push(d);
167
+ this.storage.setPersistedData(CoreApp.devicesField, devices);
168
+ }
169
+ return true;
170
+ }
171
+ // Failed, reset keys
172
+ this.resetKeys();
173
+ }
174
+ return false;
165
175
  }
166
176
  /**
167
177
  * Persist settings to source when application exit
@@ -445,6 +445,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
445
445
  */
446
446
  protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, storage: IStorage, name: string);
447
447
  private getDeviceId;
448
+ private resetKeys;
448
449
  /**
449
450
  * Restore settings from persisted source
450
451
  */
@@ -123,42 +123,52 @@ export class CoreApp {
123
123
  getDeviceId() {
124
124
  return this.deviceId.substring(0, 15);
125
125
  }
126
+ resetKeys() {
127
+ this.storage.clear([
128
+ CoreApp.devicePassphraseField,
129
+ CoreApp.headerTokenField,
130
+ CoreApp.serversideDeviceIdField
131
+ ], false);
132
+ this.passphrase = '';
133
+ }
126
134
  /**
127
135
  * Restore settings from persisted source
128
136
  */
129
137
  restore() {
138
+ // Devices
139
+ const devices = this.storage.getPersistedData(CoreApp.devicesField, []);
130
140
  // Current device id, '' means new, or reload (not included) or duplicate (included)
131
- if (this.deviceId) {
132
- // Devices
133
- const devices = this.storage.getPersistedData(CoreApp.devicesField, []);
134
- // Exists in the list?
141
+ if (this.deviceId === '') {
142
+ // First vist, restore
143
+ this.storage.copyFrom(this.persistedFields, true);
144
+ // Reset device id
145
+ this._deviceId = this.storage.getData(CoreApp.deviceIdField, '');
146
+ }
147
+ else {
135
148
  const d = this.getDeviceId();
136
- if (!devices.includes(d)) {
137
- const passphraseEncrypted = this.storage.getData(CoreApp.devicePassphraseField);
138
- if (passphraseEncrypted) {
139
- const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
140
- if (passphraseDecrypted != null) {
141
- this.passphrase = passphraseDecrypted;
142
- devices.push(d);
143
- this.storage.setPersistedData(CoreApp.devicesField, devices);
144
- return false;
145
- }
146
- }
147
- }
148
- else {
149
+ if (devices.includes(d)) {
149
150
  // Duplicate tab, session data copied
150
151
  // Remove the token, deviceId, and passphrase
151
- this.storage.clear([
152
- CoreApp.devicePassphraseField,
153
- CoreApp.headerTokenField,
154
- CoreApp.serversideDeviceIdField
155
- ], false);
156
- this.passphrase = '';
152
+ this.resetKeys();
153
+ return false;
157
154
  }
158
155
  }
159
- // Restore
160
- this.storage.copyFrom(this.persistedFields, true);
161
- return true;
156
+ const passphraseEncrypted = this.storage.getData(CoreApp.devicePassphraseField);
157
+ if (passphraseEncrypted) {
158
+ const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
159
+ if (passphraseDecrypted != null) {
160
+ this.passphrase = passphraseDecrypted;
161
+ const d = this.getDeviceId();
162
+ if (!devices.includes(d)) {
163
+ devices.push(d);
164
+ this.storage.setPersistedData(CoreApp.devicesField, devices);
165
+ }
166
+ return true;
167
+ }
168
+ // Failed, reset keys
169
+ this.resetKeys();
170
+ }
171
+ return false;
162
172
  }
163
173
  /**
164
174
  * Persist settings to source when application exit
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -654,60 +654,74 @@ export abstract class CoreApp<
654
654
  return this.deviceId.substring(0, 15);
655
655
  }
656
656
 
657
+ private resetKeys() {
658
+ this.storage.clear(
659
+ [
660
+ CoreApp.devicePassphraseField,
661
+ CoreApp.headerTokenField,
662
+ CoreApp.serversideDeviceIdField
663
+ ],
664
+ false
665
+ );
666
+ this.passphrase = '';
667
+ }
668
+
657
669
  /**
658
670
  * Restore settings from persisted source
659
671
  */
660
672
  protected restore() {
673
+ // Devices
674
+ const devices = this.storage.getPersistedData<string[]>(
675
+ CoreApp.devicesField,
676
+ []
677
+ );
678
+
661
679
  // Current device id, '' means new, or reload (not included) or duplicate (included)
662
- if (this.deviceId) {
663
- // Devices
664
- const devices = this.storage.getPersistedData<string[]>(
665
- CoreApp.devicesField,
666
- []
667
- );
680
+ if (this.deviceId === '') {
681
+ // First vist, restore
682
+ this.storage.copyFrom(this.persistedFields, true);
668
683
 
669
- // Exists in the list?
684
+ // Reset device id
685
+ this._deviceId = this.storage.getData(CoreApp.deviceIdField, '');
686
+ } else {
670
687
  const d = this.getDeviceId();
671
- if (!devices.includes(d)) {
672
- const passphraseEncrypted = this.storage.getData<string>(
673
- CoreApp.devicePassphraseField
674
- );
675
- if (passphraseEncrypted) {
676
- const passphraseDecrypted = this.decrypt(
677
- passphraseEncrypted,
678
- this.name
679
- );
680
- if (passphraseDecrypted != null) {
681
- this.passphrase = passphraseDecrypted;
682
-
683
- devices.push(d);
684
- this.storage.setPersistedData(
685
- CoreApp.devicesField,
686
- devices
687
- );
688
688
 
689
- return false;
690
- }
691
- }
692
- } else {
689
+ if (devices.includes(d)) {
693
690
  // Duplicate tab, session data copied
694
691
  // Remove the token, deviceId, and passphrase
695
- this.storage.clear(
696
- [
697
- CoreApp.devicePassphraseField,
698
- CoreApp.headerTokenField,
699
- CoreApp.serversideDeviceIdField
700
- ],
701
- false
702
- );
703
- this.passphrase = '';
692
+ this.resetKeys();
693
+ return false;
704
694
  }
705
695
  }
706
696
 
707
- // Restore
708
- this.storage.copyFrom(this.persistedFields, true);
697
+ const passphraseEncrypted = this.storage.getData<string>(
698
+ CoreApp.devicePassphraseField
699
+ );
700
+ if (passphraseEncrypted) {
701
+ const passphraseDecrypted = this.decrypt(
702
+ passphraseEncrypted,
703
+ this.name
704
+ );
705
+ if (passphraseDecrypted != null) {
706
+ this.passphrase = passphraseDecrypted;
707
+
708
+ const d = this.getDeviceId();
709
+ if (!devices.includes(d)) {
710
+ devices.push(d);
711
+ this.storage.setPersistedData(
712
+ CoreApp.devicesField,
713
+ devices
714
+ );
715
+ }
709
716
 
710
- return true;
717
+ return true;
718
+ }
719
+
720
+ // Failed, reset keys
721
+ this.resetKeys();
722
+ }
723
+
724
+ return false;
711
725
  }
712
726
 
713
727
  /**