@etsoo/appscript 1.2.3 → 1.2.4
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.
- package/lib/cjs/app/CoreApp.d.ts +5 -0
- package/lib/cjs/app/CoreApp.js +40 -12
- package/lib/mjs/app/CoreApp.d.ts +5 -0
- package/lib/mjs/app/CoreApp.js +40 -12
- package/package.json +1 -1
- package/src/app/CoreApp.ts +56 -21
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -444,6 +444,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
444
444
|
* @param name Application name
|
|
445
445
|
*/
|
|
446
446
|
protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, storage: IStorage, name: string);
|
|
447
|
+
private getDeviceId;
|
|
447
448
|
/**
|
|
448
449
|
* Restore settings from persisted source
|
|
449
450
|
*/
|
|
@@ -743,6 +744,10 @@ export declare namespace CoreApp {
|
|
|
743
744
|
* Device id field name
|
|
744
745
|
*/
|
|
745
746
|
const deviceIdField = "SmartERPDeviceId";
|
|
747
|
+
/**
|
|
748
|
+
* Devices field name
|
|
749
|
+
*/
|
|
750
|
+
const devicesField = "SmartERPDevices";
|
|
746
751
|
/**
|
|
747
752
|
* Device passphrase field name
|
|
748
753
|
*/
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -44,10 +44,10 @@ class CoreApp {
|
|
|
44
44
|
this.notifier = notifier;
|
|
45
45
|
this.storage = storage;
|
|
46
46
|
this.name = name;
|
|
47
|
-
// Restore
|
|
48
|
-
this.restore();
|
|
49
47
|
// Device id
|
|
50
48
|
this._deviceId = storage.getData(CoreApp.deviceIdField, '');
|
|
49
|
+
// Restore
|
|
50
|
+
this.restore();
|
|
51
51
|
this.setApi(api);
|
|
52
52
|
const { currentCulture, currentRegion } = settings;
|
|
53
53
|
this.changeCulture(currentCulture);
|
|
@@ -122,21 +122,32 @@ class CoreApp {
|
|
|
122
122
|
CoreApp.headerTokenField
|
|
123
123
|
];
|
|
124
124
|
}
|
|
125
|
+
getDeviceId() {
|
|
126
|
+
return this.deviceId.substring(0, 10);
|
|
127
|
+
}
|
|
125
128
|
/**
|
|
126
129
|
* Restore settings from persisted source
|
|
127
130
|
*/
|
|
128
131
|
restore() {
|
|
129
|
-
|
|
130
|
-
if (
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
this.
|
|
132
|
+
// Current device id, '' means new, or reload (not included) or duplicate (included)
|
|
133
|
+
if (this.deviceId) {
|
|
134
|
+
// Devices
|
|
135
|
+
const devices = this.storage.getPersistedData(CoreApp.devicesField);
|
|
136
|
+
// Exists in the list?
|
|
137
|
+
if (!(devices === null || devices === void 0 ? void 0 : devices.includes(this.getDeviceId()))) {
|
|
138
|
+
const passphraseEncrypted = this.storage.getData(CoreApp.devicePassphraseField);
|
|
139
|
+
if (passphraseEncrypted) {
|
|
140
|
+
const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
|
|
141
|
+
if (passphraseDecrypted != null) {
|
|
142
|
+
this.passphrase = passphraseDecrypted;
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
138
145
|
}
|
|
139
|
-
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
// Remove passphrase
|
|
149
|
+
this.storage.setData(CoreApp.devicePassphraseField, undefined);
|
|
150
|
+
this.passphrase = '';
|
|
140
151
|
}
|
|
141
152
|
}
|
|
142
153
|
// Restore
|
|
@@ -147,6 +158,15 @@ class CoreApp {
|
|
|
147
158
|
* Persist settings to source when application exit
|
|
148
159
|
*/
|
|
149
160
|
persist() {
|
|
161
|
+
// Devices
|
|
162
|
+
const devices = this.storage.getPersistedData(CoreApp.devicesField);
|
|
163
|
+
if (devices != null) {
|
|
164
|
+
const index = devices.indexOf(this.getDeviceId());
|
|
165
|
+
if (index !== -1) {
|
|
166
|
+
devices.splice(index, 1);
|
|
167
|
+
this.storage.setPersistedData(CoreApp.devicesField, devices);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
150
170
|
if (!this.authorized)
|
|
151
171
|
return;
|
|
152
172
|
this.storage.copyTo(this.persistedFields);
|
|
@@ -267,6 +287,10 @@ class CoreApp {
|
|
|
267
287
|
// Update device id and cache it
|
|
268
288
|
this._deviceId = data.deviceId;
|
|
269
289
|
this.storage.setData(CoreApp.deviceIdField, this._deviceId);
|
|
290
|
+
// Devices
|
|
291
|
+
const devices = this.storage.getPersistedData(CoreApp.devicesField, []);
|
|
292
|
+
devices.push(this.getDeviceId());
|
|
293
|
+
this.storage.setPersistedData(CoreApp.devicesField, devices);
|
|
270
294
|
// Current passphrase
|
|
271
295
|
this.passphrase = passphrase;
|
|
272
296
|
this.storage.setData(CoreApp.devicePassphraseField, this.encrypt(passphrase, this.name));
|
|
@@ -922,6 +946,10 @@ exports.CoreApp = CoreApp;
|
|
|
922
946
|
* Device id field name
|
|
923
947
|
*/
|
|
924
948
|
CoreApp.deviceIdField = 'SmartERPDeviceId';
|
|
949
|
+
/**
|
|
950
|
+
* Devices field name
|
|
951
|
+
*/
|
|
952
|
+
CoreApp.devicesField = 'SmartERPDevices';
|
|
925
953
|
/**
|
|
926
954
|
* Device passphrase field name
|
|
927
955
|
*/
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -444,6 +444,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
444
444
|
* @param name Application name
|
|
445
445
|
*/
|
|
446
446
|
protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, storage: IStorage, name: string);
|
|
447
|
+
private getDeviceId;
|
|
447
448
|
/**
|
|
448
449
|
* Restore settings from persisted source
|
|
449
450
|
*/
|
|
@@ -743,6 +744,10 @@ export declare namespace CoreApp {
|
|
|
743
744
|
* Device id field name
|
|
744
745
|
*/
|
|
745
746
|
const deviceIdField = "SmartERPDeviceId";
|
|
747
|
+
/**
|
|
748
|
+
* Devices field name
|
|
749
|
+
*/
|
|
750
|
+
const devicesField = "SmartERPDevices";
|
|
746
751
|
/**
|
|
747
752
|
* Device passphrase field name
|
|
748
753
|
*/
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -41,10 +41,10 @@ export class CoreApp {
|
|
|
41
41
|
this.notifier = notifier;
|
|
42
42
|
this.storage = storage;
|
|
43
43
|
this.name = name;
|
|
44
|
-
// Restore
|
|
45
|
-
this.restore();
|
|
46
44
|
// Device id
|
|
47
45
|
this._deviceId = storage.getData(CoreApp.deviceIdField, '');
|
|
46
|
+
// Restore
|
|
47
|
+
this.restore();
|
|
48
48
|
this.setApi(api);
|
|
49
49
|
const { currentCulture, currentRegion } = settings;
|
|
50
50
|
this.changeCulture(currentCulture);
|
|
@@ -119,21 +119,32 @@ export class CoreApp {
|
|
|
119
119
|
CoreApp.headerTokenField
|
|
120
120
|
];
|
|
121
121
|
}
|
|
122
|
+
getDeviceId() {
|
|
123
|
+
return this.deviceId.substring(0, 10);
|
|
124
|
+
}
|
|
122
125
|
/**
|
|
123
126
|
* Restore settings from persisted source
|
|
124
127
|
*/
|
|
125
128
|
restore() {
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.
|
|
129
|
+
// Current device id, '' means new, or reload (not included) or duplicate (included)
|
|
130
|
+
if (this.deviceId) {
|
|
131
|
+
// Devices
|
|
132
|
+
const devices = this.storage.getPersistedData(CoreApp.devicesField);
|
|
133
|
+
// Exists in the list?
|
|
134
|
+
if (!(devices === null || devices === void 0 ? void 0 : devices.includes(this.getDeviceId()))) {
|
|
135
|
+
const passphraseEncrypted = this.storage.getData(CoreApp.devicePassphraseField);
|
|
136
|
+
if (passphraseEncrypted) {
|
|
137
|
+
const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
|
|
138
|
+
if (passphraseDecrypted != null) {
|
|
139
|
+
this.passphrase = passphraseDecrypted;
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
135
142
|
}
|
|
136
|
-
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
// Remove passphrase
|
|
146
|
+
this.storage.setData(CoreApp.devicePassphraseField, undefined);
|
|
147
|
+
this.passphrase = '';
|
|
137
148
|
}
|
|
138
149
|
}
|
|
139
150
|
// Restore
|
|
@@ -144,6 +155,15 @@ export class CoreApp {
|
|
|
144
155
|
* Persist settings to source when application exit
|
|
145
156
|
*/
|
|
146
157
|
persist() {
|
|
158
|
+
// Devices
|
|
159
|
+
const devices = this.storage.getPersistedData(CoreApp.devicesField);
|
|
160
|
+
if (devices != null) {
|
|
161
|
+
const index = devices.indexOf(this.getDeviceId());
|
|
162
|
+
if (index !== -1) {
|
|
163
|
+
devices.splice(index, 1);
|
|
164
|
+
this.storage.setPersistedData(CoreApp.devicesField, devices);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
147
167
|
if (!this.authorized)
|
|
148
168
|
return;
|
|
149
169
|
this.storage.copyTo(this.persistedFields);
|
|
@@ -264,6 +284,10 @@ export class CoreApp {
|
|
|
264
284
|
// Update device id and cache it
|
|
265
285
|
this._deviceId = data.deviceId;
|
|
266
286
|
this.storage.setData(CoreApp.deviceIdField, this._deviceId);
|
|
287
|
+
// Devices
|
|
288
|
+
const devices = this.storage.getPersistedData(CoreApp.devicesField, []);
|
|
289
|
+
devices.push(this.getDeviceId());
|
|
290
|
+
this.storage.setPersistedData(CoreApp.devicesField, devices);
|
|
267
291
|
// Current passphrase
|
|
268
292
|
this.passphrase = passphrase;
|
|
269
293
|
this.storage.setData(CoreApp.devicePassphraseField, this.encrypt(passphrase, this.name));
|
|
@@ -918,6 +942,10 @@ export class CoreApp {
|
|
|
918
942
|
* Device id field name
|
|
919
943
|
*/
|
|
920
944
|
CoreApp.deviceIdField = 'SmartERPDeviceId';
|
|
945
|
+
/**
|
|
946
|
+
* Devices field name
|
|
947
|
+
*/
|
|
948
|
+
CoreApp.devicesField = 'SmartERPDevices';
|
|
921
949
|
/**
|
|
922
950
|
* Device passphrase field name
|
|
923
951
|
*/
|
package/package.json
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -632,12 +632,12 @@ export abstract class CoreApp<
|
|
|
632
632
|
this.storage = storage;
|
|
633
633
|
this.name = name;
|
|
634
634
|
|
|
635
|
-
// Restore
|
|
636
|
-
this.restore();
|
|
637
|
-
|
|
638
635
|
// Device id
|
|
639
636
|
this._deviceId = storage.getData(CoreApp.deviceIdField, '');
|
|
640
637
|
|
|
638
|
+
// Restore
|
|
639
|
+
this.restore();
|
|
640
|
+
|
|
641
641
|
this.setApi(api);
|
|
642
642
|
|
|
643
643
|
const { currentCulture, currentRegion } = settings;
|
|
@@ -649,30 +649,40 @@ export abstract class CoreApp<
|
|
|
649
649
|
this.setup();
|
|
650
650
|
}
|
|
651
651
|
|
|
652
|
+
private getDeviceId() {
|
|
653
|
+
return this.deviceId.substring(0, 10);
|
|
654
|
+
}
|
|
655
|
+
|
|
652
656
|
/**
|
|
653
657
|
* Restore settings from persisted source
|
|
654
658
|
*/
|
|
655
659
|
protected restore() {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
passphraseEncrypted,
|
|
662
|
-
this.name
|
|
660
|
+
// Current device id, '' means new, or reload (not included) or duplicate (included)
|
|
661
|
+
if (this.deviceId) {
|
|
662
|
+
// Devices
|
|
663
|
+
const devices = this.storage.getPersistedData<string[]>(
|
|
664
|
+
CoreApp.devicesField
|
|
663
665
|
);
|
|
664
|
-
if (passphraseDecrypted != null) {
|
|
665
|
-
this.passphrase = passphraseDecrypted;
|
|
666
|
-
|
|
667
|
-
// Same device
|
|
668
|
-
if (
|
|
669
|
-
this.deviceId ===
|
|
670
|
-
this.storage.getPersistedData<string>(CoreApp.deviceIdField)
|
|
671
|
-
) {
|
|
672
|
-
this.storage.clear(this.persistedFields, true);
|
|
673
|
-
}
|
|
674
666
|
|
|
675
|
-
|
|
667
|
+
// Exists in the list?
|
|
668
|
+
if (!devices?.includes(this.getDeviceId())) {
|
|
669
|
+
const passphraseEncrypted = this.storage.getData<string>(
|
|
670
|
+
CoreApp.devicePassphraseField
|
|
671
|
+
);
|
|
672
|
+
if (passphraseEncrypted) {
|
|
673
|
+
const passphraseDecrypted = this.decrypt(
|
|
674
|
+
passphraseEncrypted,
|
|
675
|
+
this.name
|
|
676
|
+
);
|
|
677
|
+
if (passphraseDecrypted != null) {
|
|
678
|
+
this.passphrase = passphraseDecrypted;
|
|
679
|
+
return false;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
} else {
|
|
683
|
+
// Remove passphrase
|
|
684
|
+
this.storage.setData(CoreApp.devicePassphraseField, undefined);
|
|
685
|
+
this.passphrase = '';
|
|
676
686
|
}
|
|
677
687
|
}
|
|
678
688
|
|
|
@@ -686,6 +696,18 @@ export abstract class CoreApp<
|
|
|
686
696
|
* Persist settings to source when application exit
|
|
687
697
|
*/
|
|
688
698
|
persist() {
|
|
699
|
+
// Devices
|
|
700
|
+
const devices = this.storage.getPersistedData<string[]>(
|
|
701
|
+
CoreApp.devicesField
|
|
702
|
+
);
|
|
703
|
+
if (devices != null) {
|
|
704
|
+
const index = devices.indexOf(this.getDeviceId());
|
|
705
|
+
if (index !== -1) {
|
|
706
|
+
devices.splice(index, 1);
|
|
707
|
+
this.storage.setPersistedData(CoreApp.devicesField, devices);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
689
711
|
if (!this.authorized) return;
|
|
690
712
|
this.storage.copyTo(this.persistedFields);
|
|
691
713
|
}
|
|
@@ -823,6 +845,14 @@ export abstract class CoreApp<
|
|
|
823
845
|
this._deviceId = data.deviceId;
|
|
824
846
|
this.storage.setData(CoreApp.deviceIdField, this._deviceId);
|
|
825
847
|
|
|
848
|
+
// Devices
|
|
849
|
+
const devices = this.storage.getPersistedData<string[]>(
|
|
850
|
+
CoreApp.devicesField,
|
|
851
|
+
[]
|
|
852
|
+
);
|
|
853
|
+
devices.push(this.getDeviceId());
|
|
854
|
+
this.storage.setPersistedData(CoreApp.devicesField, devices);
|
|
855
|
+
|
|
826
856
|
// Current passphrase
|
|
827
857
|
this.passphrase = passphrase;
|
|
828
858
|
this.storage.setData(
|
|
@@ -1617,6 +1647,11 @@ export namespace CoreApp {
|
|
|
1617
1647
|
*/
|
|
1618
1648
|
export const deviceIdField = 'SmartERPDeviceId';
|
|
1619
1649
|
|
|
1650
|
+
/**
|
|
1651
|
+
* Devices field name
|
|
1652
|
+
*/
|
|
1653
|
+
export const devicesField = 'SmartERPDevices';
|
|
1654
|
+
|
|
1620
1655
|
/**
|
|
1621
1656
|
* Device passphrase field name
|
|
1622
1657
|
*/
|