@etsoo/appscript 1.5.22 → 1.5.23

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.
@@ -135,6 +135,8 @@ class CoreAppTest extends CoreApp<
135
135
  new WindowStorage(),
136
136
  'SmartERP'
137
137
  );
138
+
139
+ this.deviceId = 'abcd1234';
138
140
  }
139
141
 
140
142
  freshCountdownUI(callback?: () => PromiseLike<unknown>): void {
@@ -90,6 +90,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
90
90
  * Device id, randome string from ServiceBase.InitCallAsync
91
91
  */
92
92
  get deviceId(): string;
93
+ protected set deviceId(value: string);
93
94
  /**
94
95
  * Label delegate
95
96
  */
@@ -251,6 +252,11 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
251
252
  * @returns Result
252
253
  */
253
254
  initCall(callback?: (result: boolean) => void, resetKeys?: boolean): Promise<void>;
255
+ /**
256
+ * Update passphrase
257
+ * @param passphrase Secret passphrase
258
+ */
259
+ protected updatePassphrase(passphrase: string): void;
254
260
  /**
255
261
  * Init call update
256
262
  * @param data Result data
@@ -39,8 +39,14 @@ class CoreApp {
39
39
  * Device id, randome string from ServiceBase.InitCallAsync
40
40
  */
41
41
  get deviceId() {
42
+ if (this._deviceId === '') {
43
+ throw new Error('Device id is empty');
44
+ }
42
45
  return this._deviceId;
43
46
  }
47
+ set deviceId(value) {
48
+ this._deviceId = value;
49
+ }
44
50
  /**
45
51
  * Label delegate
46
52
  */
@@ -529,33 +535,16 @@ class CoreApp {
529
535
  callback(updateResult);
530
536
  }
531
537
  /**
532
- * Init call update
533
- * @param data Result data
534
- * @param timestamp Timestamp
538
+ * Update passphrase
539
+ * @param passphrase Secret passphrase
535
540
  */
536
- async initCallUpdate(data, timestamp) {
537
- // Data check
538
- if (data.deviceId == null || data.passphrase == null)
539
- return false;
540
- // Decrypt
541
- // Should be done within 120 seconds after returning from the backend
542
- const passphrase = this.decrypt(data.passphrase, timestamp.toString());
543
- if (passphrase == null)
544
- return false;
545
- // Update device id and cache it
546
- this._deviceId = data.deviceId;
547
- this.storage.setData(this.fields.deviceId, this._deviceId);
548
- // Devices
549
- const devices = this.storage.getPersistedData(this.fields.devices, []);
550
- devices.push(this.getDeviceId());
551
- this.storage.setPersistedData(this.fields.devices, devices);
552
- // Current passphrase
541
+ updatePassphrase(passphrase) {
542
+ // Previous passphrase
543
+ const prev = this.passphrase;
544
+ // Update
553
545
  this.passphrase = passphrase;
554
546
  this.storage.setData(this.fields.devicePassphrase, this.encrypt(passphrase, this.name));
555
- // Previous passphrase
556
- if (data.previousPassphrase) {
557
- const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
558
- // Update
547
+ if (prev) {
559
548
  const fields = this.initCallEncryptedUpdateFields();
560
549
  for (const field of fields) {
561
550
  const currentValue = this.storage.getData(field);
@@ -585,6 +574,35 @@ class CoreApp {
585
574
  this.storage.setData(field, newValue);
586
575
  }
587
576
  }
577
+ }
578
+ /**
579
+ * Init call update
580
+ * @param data Result data
581
+ * @param timestamp Timestamp
582
+ */
583
+ async initCallUpdate(data, timestamp) {
584
+ // Data check
585
+ if (data.deviceId == null || data.passphrase == null)
586
+ return false;
587
+ // Decrypt
588
+ // Should be done within 120 seconds after returning from the backend
589
+ const passphrase = this.decrypt(data.passphrase, timestamp.toString());
590
+ if (passphrase == null)
591
+ return false;
592
+ // Update device id and cache it
593
+ this._deviceId = data.deviceId;
594
+ this.storage.setData(this.fields.deviceId, this._deviceId);
595
+ // Devices
596
+ const devices = this.storage.getPersistedData(this.fields.devices, []);
597
+ devices.push(this.getDeviceId());
598
+ this.storage.setPersistedData(this.fields.devices, devices);
599
+ // Previous passphrase
600
+ if (data.previousPassphrase) {
601
+ const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
602
+ this.passphrase = prev ?? '';
603
+ }
604
+ // Update passphrase
605
+ this.updatePassphrase(passphrase);
588
606
  return true;
589
607
  }
590
608
  /**
@@ -90,6 +90,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
90
90
  * Device id, randome string from ServiceBase.InitCallAsync
91
91
  */
92
92
  get deviceId(): string;
93
+ protected set deviceId(value: string);
93
94
  /**
94
95
  * Label delegate
95
96
  */
@@ -251,6 +252,11 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
251
252
  * @returns Result
252
253
  */
253
254
  initCall(callback?: (result: boolean) => void, resetKeys?: boolean): Promise<void>;
255
+ /**
256
+ * Update passphrase
257
+ * @param passphrase Secret passphrase
258
+ */
259
+ protected updatePassphrase(passphrase: string): void;
254
260
  /**
255
261
  * Init call update
256
262
  * @param data Result data
@@ -36,8 +36,14 @@ export class CoreApp {
36
36
  * Device id, randome string from ServiceBase.InitCallAsync
37
37
  */
38
38
  get deviceId() {
39
+ if (this._deviceId === '') {
40
+ throw new Error('Device id is empty');
41
+ }
39
42
  return this._deviceId;
40
43
  }
44
+ set deviceId(value) {
45
+ this._deviceId = value;
46
+ }
41
47
  /**
42
48
  * Label delegate
43
49
  */
@@ -526,33 +532,16 @@ export class CoreApp {
526
532
  callback(updateResult);
527
533
  }
528
534
  /**
529
- * Init call update
530
- * @param data Result data
531
- * @param timestamp Timestamp
535
+ * Update passphrase
536
+ * @param passphrase Secret passphrase
532
537
  */
533
- async initCallUpdate(data, timestamp) {
534
- // Data check
535
- if (data.deviceId == null || data.passphrase == null)
536
- return false;
537
- // Decrypt
538
- // Should be done within 120 seconds after returning from the backend
539
- const passphrase = this.decrypt(data.passphrase, timestamp.toString());
540
- if (passphrase == null)
541
- return false;
542
- // Update device id and cache it
543
- this._deviceId = data.deviceId;
544
- this.storage.setData(this.fields.deviceId, this._deviceId);
545
- // Devices
546
- const devices = this.storage.getPersistedData(this.fields.devices, []);
547
- devices.push(this.getDeviceId());
548
- this.storage.setPersistedData(this.fields.devices, devices);
549
- // Current passphrase
538
+ updatePassphrase(passphrase) {
539
+ // Previous passphrase
540
+ const prev = this.passphrase;
541
+ // Update
550
542
  this.passphrase = passphrase;
551
543
  this.storage.setData(this.fields.devicePassphrase, this.encrypt(passphrase, this.name));
552
- // Previous passphrase
553
- if (data.previousPassphrase) {
554
- const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
555
- // Update
544
+ if (prev) {
556
545
  const fields = this.initCallEncryptedUpdateFields();
557
546
  for (const field of fields) {
558
547
  const currentValue = this.storage.getData(field);
@@ -582,6 +571,35 @@ export class CoreApp {
582
571
  this.storage.setData(field, newValue);
583
572
  }
584
573
  }
574
+ }
575
+ /**
576
+ * Init call update
577
+ * @param data Result data
578
+ * @param timestamp Timestamp
579
+ */
580
+ async initCallUpdate(data, timestamp) {
581
+ // Data check
582
+ if (data.deviceId == null || data.passphrase == null)
583
+ return false;
584
+ // Decrypt
585
+ // Should be done within 120 seconds after returning from the backend
586
+ const passphrase = this.decrypt(data.passphrase, timestamp.toString());
587
+ if (passphrase == null)
588
+ return false;
589
+ // Update device id and cache it
590
+ this._deviceId = data.deviceId;
591
+ this.storage.setData(this.fields.deviceId, this._deviceId);
592
+ // Devices
593
+ const devices = this.storage.getPersistedData(this.fields.devices, []);
594
+ devices.push(this.getDeviceId());
595
+ this.storage.setPersistedData(this.fields.devices, devices);
596
+ // Previous passphrase
597
+ if (data.previousPassphrase) {
598
+ const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
599
+ this.passphrase = prev ?? '';
600
+ }
601
+ // Update passphrase
602
+ this.updatePassphrase(passphrase);
585
603
  return true;
586
604
  }
587
605
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.5.22",
3
+ "version": "1.5.23",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -170,8 +170,14 @@ export abstract class CoreApp<
170
170
  * Device id, randome string from ServiceBase.InitCallAsync
171
171
  */
172
172
  get deviceId() {
173
+ if (this._deviceId === '') {
174
+ throw new Error('Device id is empty');
175
+ }
173
176
  return this._deviceId;
174
177
  }
178
+ protected set deviceId(value: string) {
179
+ this._deviceId = value;
180
+ }
175
181
 
176
182
  /**
177
183
  * Label delegate
@@ -837,49 +843,21 @@ export abstract class CoreApp<
837
843
  }
838
844
 
839
845
  /**
840
- * Init call update
841
- * @param data Result data
842
- * @param timestamp Timestamp
846
+ * Update passphrase
847
+ * @param passphrase Secret passphrase
843
848
  */
844
- protected async initCallUpdate(
845
- data: InitCallResultData,
846
- timestamp: number
847
- ): Promise<boolean> {
848
- // Data check
849
- if (data.deviceId == null || data.passphrase == null) return false;
850
-
851
- // Decrypt
852
- // Should be done within 120 seconds after returning from the backend
853
- const passphrase = this.decrypt(data.passphrase, timestamp.toString());
854
- if (passphrase == null) return false;
855
-
856
- // Update device id and cache it
857
- this._deviceId = data.deviceId;
858
- this.storage.setData(this.fields.deviceId, this._deviceId);
859
-
860
- // Devices
861
- const devices = this.storage.getPersistedData<string[]>(
862
- this.fields.devices,
863
- []
864
- );
865
- devices.push(this.getDeviceId());
866
- this.storage.setPersistedData(this.fields.devices, devices);
849
+ protected updatePassphrase(passphrase: string) {
850
+ // Previous passphrase
851
+ const prev = this.passphrase;
867
852
 
868
- // Current passphrase
853
+ // Update
869
854
  this.passphrase = passphrase;
870
855
  this.storage.setData(
871
856
  this.fields.devicePassphrase,
872
857
  this.encrypt(passphrase, this.name)
873
858
  );
874
859
 
875
- // Previous passphrase
876
- if (data.previousPassphrase) {
877
- const prev = this.decrypt(
878
- data.previousPassphrase,
879
- timestamp.toString()
880
- );
881
-
882
- // Update
860
+ if (prev) {
883
861
  const fields = this.initCallEncryptedUpdateFields();
884
862
  for (const field of fields) {
885
863
  const currentValue = this.storage.getData<string>(field);
@@ -917,6 +895,48 @@ export abstract class CoreApp<
917
895
  this.storage.setData(field, newValue);
918
896
  }
919
897
  }
898
+ }
899
+
900
+ /**
901
+ * Init call update
902
+ * @param data Result data
903
+ * @param timestamp Timestamp
904
+ */
905
+ protected async initCallUpdate(
906
+ data: InitCallResultData,
907
+ timestamp: number
908
+ ): Promise<boolean> {
909
+ // Data check
910
+ if (data.deviceId == null || data.passphrase == null) return false;
911
+
912
+ // Decrypt
913
+ // Should be done within 120 seconds after returning from the backend
914
+ const passphrase = this.decrypt(data.passphrase, timestamp.toString());
915
+ if (passphrase == null) return false;
916
+
917
+ // Update device id and cache it
918
+ this._deviceId = data.deviceId;
919
+ this.storage.setData(this.fields.deviceId, this._deviceId);
920
+
921
+ // Devices
922
+ const devices = this.storage.getPersistedData<string[]>(
923
+ this.fields.devices,
924
+ []
925
+ );
926
+ devices.push(this.getDeviceId());
927
+ this.storage.setPersistedData(this.fields.devices, devices);
928
+
929
+ // Previous passphrase
930
+ if (data.previousPassphrase) {
931
+ const prev = this.decrypt(
932
+ data.previousPassphrase,
933
+ timestamp.toString()
934
+ );
935
+ this.passphrase = prev ?? '';
936
+ }
937
+
938
+ // Update passphrase
939
+ this.updatePassphrase(passphrase);
920
940
 
921
941
  return true;
922
942
  }