@etsoo/appscript 1.2.2 → 1.2.7
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 +54 -12
- package/lib/mjs/app/CoreApp.d.ts +5 -0
- package/lib/mjs/app/CoreApp.js +54 -12
- package/package.json +2 -2
- package/src/app/CoreApp.ts +78 -17
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);
|
|
@@ -118,33 +118,67 @@ class CoreApp {
|
|
|
118
118
|
get persistedFields() {
|
|
119
119
|
return [
|
|
120
120
|
CoreApp.deviceIdField,
|
|
121
|
+
CoreApp.devicePassphraseField,
|
|
121
122
|
CoreApp.serversideDeviceIdField,
|
|
122
123
|
CoreApp.headerTokenField
|
|
123
124
|
];
|
|
124
125
|
}
|
|
126
|
+
getDeviceId() {
|
|
127
|
+
return this.deviceId.substring(0, 15);
|
|
128
|
+
}
|
|
125
129
|
/**
|
|
126
130
|
* Restore settings from persisted source
|
|
127
131
|
*/
|
|
128
132
|
restore() {
|
|
129
|
-
|
|
130
|
-
if (
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
// 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?
|
|
138
|
+
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
|
+
// Duplicate tab, session data copied
|
|
153
|
+
// Remove the token, deviceId, and passphrase
|
|
154
|
+
this.storage.clear([
|
|
155
|
+
CoreApp.devicePassphraseField,
|
|
156
|
+
CoreApp.headerTokenField,
|
|
157
|
+
CoreApp.serversideDeviceIdField
|
|
158
|
+
], false);
|
|
159
|
+
this.passphrase = '';
|
|
135
160
|
}
|
|
136
161
|
}
|
|
137
162
|
// Restore
|
|
138
|
-
this.storage.
|
|
163
|
+
this.storage.copyFrom(this.persistedFields, true);
|
|
139
164
|
return true;
|
|
140
165
|
}
|
|
141
166
|
/**
|
|
142
167
|
* Persist settings to source when application exit
|
|
143
168
|
*/
|
|
144
169
|
persist() {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
170
|
+
// Devices
|
|
171
|
+
const devices = this.storage.getPersistedData(CoreApp.devicesField);
|
|
172
|
+
if (devices != null) {
|
|
173
|
+
const index = devices.indexOf(this.getDeviceId());
|
|
174
|
+
if (index !== -1) {
|
|
175
|
+
devices.splice(index, 1);
|
|
176
|
+
this.storage.setPersistedData(CoreApp.devicesField, devices);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (!this.authorized)
|
|
180
|
+
return;
|
|
181
|
+
this.storage.copyTo(this.persistedFields);
|
|
148
182
|
}
|
|
149
183
|
/**
|
|
150
184
|
* Setup Api
|
|
@@ -262,6 +296,10 @@ class CoreApp {
|
|
|
262
296
|
// Update device id and cache it
|
|
263
297
|
this._deviceId = data.deviceId;
|
|
264
298
|
this.storage.setData(CoreApp.deviceIdField, this._deviceId);
|
|
299
|
+
// Devices
|
|
300
|
+
const devices = this.storage.getPersistedData(CoreApp.devicesField, []);
|
|
301
|
+
devices.push(this.getDeviceId());
|
|
302
|
+
this.storage.setPersistedData(CoreApp.devicesField, devices);
|
|
265
303
|
// Current passphrase
|
|
266
304
|
this.passphrase = passphrase;
|
|
267
305
|
this.storage.setData(CoreApp.devicePassphraseField, this.encrypt(passphrase, this.name));
|
|
@@ -917,6 +955,10 @@ exports.CoreApp = CoreApp;
|
|
|
917
955
|
* Device id field name
|
|
918
956
|
*/
|
|
919
957
|
CoreApp.deviceIdField = 'SmartERPDeviceId';
|
|
958
|
+
/**
|
|
959
|
+
* Devices field name
|
|
960
|
+
*/
|
|
961
|
+
CoreApp.devicesField = 'SmartERPDevices';
|
|
920
962
|
/**
|
|
921
963
|
* Device passphrase field name
|
|
922
964
|
*/
|
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);
|
|
@@ -115,33 +115,67 @@ export class CoreApp {
|
|
|
115
115
|
get persistedFields() {
|
|
116
116
|
return [
|
|
117
117
|
CoreApp.deviceIdField,
|
|
118
|
+
CoreApp.devicePassphraseField,
|
|
118
119
|
CoreApp.serversideDeviceIdField,
|
|
119
120
|
CoreApp.headerTokenField
|
|
120
121
|
];
|
|
121
122
|
}
|
|
123
|
+
getDeviceId() {
|
|
124
|
+
return this.deviceId.substring(0, 15);
|
|
125
|
+
}
|
|
122
126
|
/**
|
|
123
127
|
* Restore settings from persisted source
|
|
124
128
|
*/
|
|
125
129
|
restore() {
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
// 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?
|
|
135
|
+
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
|
+
// Duplicate tab, session data copied
|
|
150
|
+
// Remove the token, deviceId, and passphrase
|
|
151
|
+
this.storage.clear([
|
|
152
|
+
CoreApp.devicePassphraseField,
|
|
153
|
+
CoreApp.headerTokenField,
|
|
154
|
+
CoreApp.serversideDeviceIdField
|
|
155
|
+
], false);
|
|
156
|
+
this.passphrase = '';
|
|
132
157
|
}
|
|
133
158
|
}
|
|
134
159
|
// Restore
|
|
135
|
-
this.storage.
|
|
160
|
+
this.storage.copyFrom(this.persistedFields, true);
|
|
136
161
|
return true;
|
|
137
162
|
}
|
|
138
163
|
/**
|
|
139
164
|
* Persist settings to source when application exit
|
|
140
165
|
*/
|
|
141
166
|
persist() {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
167
|
+
// Devices
|
|
168
|
+
const devices = this.storage.getPersistedData(CoreApp.devicesField);
|
|
169
|
+
if (devices != null) {
|
|
170
|
+
const index = devices.indexOf(this.getDeviceId());
|
|
171
|
+
if (index !== -1) {
|
|
172
|
+
devices.splice(index, 1);
|
|
173
|
+
this.storage.setPersistedData(CoreApp.devicesField, devices);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (!this.authorized)
|
|
177
|
+
return;
|
|
178
|
+
this.storage.copyTo(this.persistedFields);
|
|
145
179
|
}
|
|
146
180
|
/**
|
|
147
181
|
* Setup Api
|
|
@@ -259,6 +293,10 @@ export class CoreApp {
|
|
|
259
293
|
// Update device id and cache it
|
|
260
294
|
this._deviceId = data.deviceId;
|
|
261
295
|
this.storage.setData(CoreApp.deviceIdField, this._deviceId);
|
|
296
|
+
// Devices
|
|
297
|
+
const devices = this.storage.getPersistedData(CoreApp.devicesField, []);
|
|
298
|
+
devices.push(this.getDeviceId());
|
|
299
|
+
this.storage.setPersistedData(CoreApp.devicesField, devices);
|
|
262
300
|
// Current passphrase
|
|
263
301
|
this.passphrase = passphrase;
|
|
264
302
|
this.storage.setData(CoreApp.devicePassphraseField, this.encrypt(passphrase, this.name));
|
|
@@ -913,6 +951,10 @@ export class CoreApp {
|
|
|
913
951
|
* Device id field name
|
|
914
952
|
*/
|
|
915
953
|
CoreApp.deviceIdField = 'SmartERPDeviceId';
|
|
954
|
+
/**
|
|
955
|
+
* Devices field name
|
|
956
|
+
*/
|
|
957
|
+
CoreApp.devicesField = 'SmartERPDevices';
|
|
916
958
|
/**
|
|
917
959
|
* Device passphrase field name
|
|
918
960
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@etsoo/notificationbase": "^1.0.95",
|
|
56
56
|
"@etsoo/restclient": "^1.0.63",
|
|
57
|
-
"@etsoo/shared": "^1.0.
|
|
57
|
+
"@etsoo/shared": "^1.0.94",
|
|
58
58
|
"@types/crypto-js": "^4.0.2",
|
|
59
59
|
"crypto-js": "^4.1.1"
|
|
60
60
|
},
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -606,6 +606,7 @@ export abstract class CoreApp<
|
|
|
606
606
|
protected get persistedFields() {
|
|
607
607
|
return [
|
|
608
608
|
CoreApp.deviceIdField,
|
|
609
|
+
CoreApp.devicePassphraseField,
|
|
609
610
|
CoreApp.serversideDeviceIdField,
|
|
610
611
|
CoreApp.headerTokenField
|
|
611
612
|
];
|
|
@@ -632,12 +633,12 @@ export abstract class CoreApp<
|
|
|
632
633
|
this.storage = storage;
|
|
633
634
|
this.name = name;
|
|
634
635
|
|
|
635
|
-
// Restore
|
|
636
|
-
this.restore();
|
|
637
|
-
|
|
638
636
|
// Device id
|
|
639
637
|
this._deviceId = storage.getData(CoreApp.deviceIdField, '');
|
|
640
638
|
|
|
639
|
+
// Restore
|
|
640
|
+
this.restore();
|
|
641
|
+
|
|
641
642
|
this.setApi(api);
|
|
642
643
|
|
|
643
644
|
const { currentCulture, currentRegion } = settings;
|
|
@@ -649,26 +650,62 @@ export abstract class CoreApp<
|
|
|
649
650
|
this.setup();
|
|
650
651
|
}
|
|
651
652
|
|
|
653
|
+
private getDeviceId() {
|
|
654
|
+
return this.deviceId.substring(0, 15);
|
|
655
|
+
}
|
|
656
|
+
|
|
652
657
|
/**
|
|
653
658
|
* Restore settings from persisted source
|
|
654
659
|
*/
|
|
655
660
|
protected restore() {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
this.name
|
|
661
|
+
// 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
|
+
[]
|
|
663
667
|
);
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
668
|
+
|
|
669
|
+
// Exists in the list?
|
|
670
|
+
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
|
+
|
|
689
|
+
return false;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
} else {
|
|
693
|
+
// Duplicate tab, session data copied
|
|
694
|
+
// 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 = '';
|
|
667
704
|
}
|
|
668
705
|
}
|
|
669
706
|
|
|
670
707
|
// Restore
|
|
671
|
-
this.storage.
|
|
708
|
+
this.storage.copyFrom(this.persistedFields, true);
|
|
672
709
|
|
|
673
710
|
return true;
|
|
674
711
|
}
|
|
@@ -677,9 +714,20 @@ export abstract class CoreApp<
|
|
|
677
714
|
* Persist settings to source when application exit
|
|
678
715
|
*/
|
|
679
716
|
persist() {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
717
|
+
// Devices
|
|
718
|
+
const devices = this.storage.getPersistedData<string[]>(
|
|
719
|
+
CoreApp.devicesField
|
|
720
|
+
);
|
|
721
|
+
if (devices != null) {
|
|
722
|
+
const index = devices.indexOf(this.getDeviceId());
|
|
723
|
+
if (index !== -1) {
|
|
724
|
+
devices.splice(index, 1);
|
|
725
|
+
this.storage.setPersistedData(CoreApp.devicesField, devices);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
if (!this.authorized) return;
|
|
730
|
+
this.storage.copyTo(this.persistedFields);
|
|
683
731
|
}
|
|
684
732
|
|
|
685
733
|
/**
|
|
@@ -815,6 +863,14 @@ export abstract class CoreApp<
|
|
|
815
863
|
this._deviceId = data.deviceId;
|
|
816
864
|
this.storage.setData(CoreApp.deviceIdField, this._deviceId);
|
|
817
865
|
|
|
866
|
+
// Devices
|
|
867
|
+
const devices = this.storage.getPersistedData<string[]>(
|
|
868
|
+
CoreApp.devicesField,
|
|
869
|
+
[]
|
|
870
|
+
);
|
|
871
|
+
devices.push(this.getDeviceId());
|
|
872
|
+
this.storage.setPersistedData(CoreApp.devicesField, devices);
|
|
873
|
+
|
|
818
874
|
// Current passphrase
|
|
819
875
|
this.passphrase = passphrase;
|
|
820
876
|
this.storage.setData(
|
|
@@ -1609,6 +1665,11 @@ export namespace CoreApp {
|
|
|
1609
1665
|
*/
|
|
1610
1666
|
export const deviceIdField = 'SmartERPDeviceId';
|
|
1611
1667
|
|
|
1668
|
+
/**
|
|
1669
|
+
* Devices field name
|
|
1670
|
+
*/
|
|
1671
|
+
export const devicesField = 'SmartERPDevices';
|
|
1672
|
+
|
|
1612
1673
|
/**
|
|
1613
1674
|
* Device passphrase field name
|
|
1614
1675
|
*/
|