@etsoo/appscript 1.1.97 → 1.2.1
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/__tests__/app/CoreApp.ts +1 -1
- package/lib/cjs/app/CoreApp.d.ts +16 -0
- package/lib/cjs/app/CoreApp.js +43 -16
- package/lib/mjs/app/CoreApp.d.ts +16 -0
- package/lib/mjs/app/CoreApp.js +43 -16
- package/package.json +2 -2
- package/src/app/CoreApp.ts +68 -19
package/__tests__/app/CoreApp.ts
CHANGED
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -293,6 +293,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
293
293
|
* @returns Result
|
|
294
294
|
*/
|
|
295
295
|
orgList(items?: number, serviceId?: number): Promise<IdLabelDto[] | undefined>;
|
|
296
|
+
/**
|
|
297
|
+
* Persist settings to source when application exit
|
|
298
|
+
*/
|
|
299
|
+
persist(): void;
|
|
296
300
|
/**
|
|
297
301
|
* Switch organization
|
|
298
302
|
* @param id Organization id
|
|
@@ -436,6 +440,18 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
436
440
|
* @param name Application name
|
|
437
441
|
*/
|
|
438
442
|
protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, storage: IStorage, name: string);
|
|
443
|
+
/**
|
|
444
|
+
* Restore settings from persisted source
|
|
445
|
+
*/
|
|
446
|
+
protected restore(): boolean;
|
|
447
|
+
/**
|
|
448
|
+
* Persist settings to source when application exit
|
|
449
|
+
*/
|
|
450
|
+
persist(): void;
|
|
451
|
+
/**
|
|
452
|
+
* Setup Api
|
|
453
|
+
* @param api Api
|
|
454
|
+
*/
|
|
439
455
|
protected setApi(api: IApi): void;
|
|
440
456
|
/**
|
|
441
457
|
* Api init call
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -21,7 +21,6 @@ class CoreApp {
|
|
|
21
21
|
* @param name Application name
|
|
22
22
|
*/
|
|
23
23
|
constructor(settings, api, notifier, storage, name) {
|
|
24
|
-
var _a;
|
|
25
24
|
this._authorized = false;
|
|
26
25
|
this._isTryingLogin = false;
|
|
27
26
|
/**
|
|
@@ -39,14 +38,16 @@ class CoreApp {
|
|
|
39
38
|
/**
|
|
40
39
|
* Passphrase for encryption
|
|
41
40
|
*/
|
|
42
|
-
this.passphrase = '
|
|
41
|
+
this.passphrase = '';
|
|
43
42
|
this.settings = settings;
|
|
44
43
|
this.api = api;
|
|
45
44
|
this.notifier = notifier;
|
|
46
45
|
this.storage = storage;
|
|
47
46
|
this.name = name;
|
|
47
|
+
// Restore
|
|
48
|
+
this.restore();
|
|
48
49
|
// Device id
|
|
49
|
-
this._deviceId =
|
|
50
|
+
this._deviceId = storage.getData(CoreApp.deviceIdField, '');
|
|
50
51
|
this.setApi(api);
|
|
51
52
|
const { currentCulture, currentRegion } = settings;
|
|
52
53
|
this.changeCulture(currentCulture);
|
|
@@ -111,6 +112,38 @@ class CoreApp {
|
|
|
111
112
|
set authorized(value) {
|
|
112
113
|
this._authorized = value;
|
|
113
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Restore settings from persisted source
|
|
117
|
+
*/
|
|
118
|
+
restore() {
|
|
119
|
+
const passphraseEncrypted = this.storage.getData(CoreApp.devicePassphraseField);
|
|
120
|
+
if (passphraseEncrypted) {
|
|
121
|
+
const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
|
|
122
|
+
if (passphraseDecrypted != null) {
|
|
123
|
+
this.passphrase = passphraseDecrypted;
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Restore
|
|
128
|
+
this.storage.copy([
|
|
129
|
+
CoreApp.deviceIdField,
|
|
130
|
+
CoreApp.serversideDeviceIdField,
|
|
131
|
+
CoreApp.headerTokenField
|
|
132
|
+
], true);
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Persist settings to source when application exit
|
|
137
|
+
*/
|
|
138
|
+
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));
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Setup Api
|
|
145
|
+
* @param api Api
|
|
146
|
+
*/
|
|
114
147
|
setApi(api) {
|
|
115
148
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
116
149
|
api.onRequest = (data) => {
|
|
@@ -157,16 +190,10 @@ class CoreApp {
|
|
|
157
190
|
async initCall(callback) {
|
|
158
191
|
var _a;
|
|
159
192
|
// Passphrase exists?
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (passphraseDecrypted != null) {
|
|
165
|
-
this.passphrase = passphraseDecrypted;
|
|
166
|
-
if (callback)
|
|
167
|
-
callback(true);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
193
|
+
if (this.passphrase) {
|
|
194
|
+
if (callback)
|
|
195
|
+
callback(true);
|
|
196
|
+
return;
|
|
170
197
|
}
|
|
171
198
|
// Serverside encrypted device id
|
|
172
199
|
const identifier = this.storage.getData(CoreApp.serversideDeviceIdField);
|
|
@@ -228,7 +255,7 @@ class CoreApp {
|
|
|
228
255
|
return;
|
|
229
256
|
// Update device id and cache it
|
|
230
257
|
this._deviceId = data.deviceId;
|
|
231
|
-
this.storage.setData(CoreApp.deviceIdField, this.
|
|
258
|
+
this.storage.setData(CoreApp.deviceIdField, this._deviceId);
|
|
232
259
|
// Current passphrase
|
|
233
260
|
this.passphrase = passphrase;
|
|
234
261
|
this.storage.setData(CoreApp.devicePassphraseField, this.encrypt(passphrase, this.name));
|
|
@@ -322,7 +349,7 @@ class CoreApp {
|
|
|
322
349
|
if (regionItem == null || !this.settings.regions.includes(regionId))
|
|
323
350
|
return;
|
|
324
351
|
// Save the id to local storage
|
|
325
|
-
this.storage.
|
|
352
|
+
this.storage.setPersistedData(shared_1.DomUtils.CountryField, regionId);
|
|
326
353
|
// Set the currency and culture
|
|
327
354
|
this._currency = regionItem.currency;
|
|
328
355
|
this._region = regionId;
|
|
@@ -340,7 +367,7 @@ class CoreApp {
|
|
|
340
367
|
if (this._culture === name)
|
|
341
368
|
return;
|
|
342
369
|
// Save the cultrue to local storage
|
|
343
|
-
this.storage.
|
|
370
|
+
this.storage.setPersistedData(shared_1.DomUtils.CultureField, name);
|
|
344
371
|
// Change the API's Content-Language header
|
|
345
372
|
// .net 5 API, UseRequestLocalization, RequestCultureProviders, ContentLanguageHeaderRequestCultureProvider
|
|
346
373
|
this.api.setContentLanguage(name);
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -293,6 +293,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
293
293
|
* @returns Result
|
|
294
294
|
*/
|
|
295
295
|
orgList(items?: number, serviceId?: number): Promise<IdLabelDto[] | undefined>;
|
|
296
|
+
/**
|
|
297
|
+
* Persist settings to source when application exit
|
|
298
|
+
*/
|
|
299
|
+
persist(): void;
|
|
296
300
|
/**
|
|
297
301
|
* Switch organization
|
|
298
302
|
* @param id Organization id
|
|
@@ -436,6 +440,18 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
436
440
|
* @param name Application name
|
|
437
441
|
*/
|
|
438
442
|
protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, storage: IStorage, name: string);
|
|
443
|
+
/**
|
|
444
|
+
* Restore settings from persisted source
|
|
445
|
+
*/
|
|
446
|
+
protected restore(): boolean;
|
|
447
|
+
/**
|
|
448
|
+
* Persist settings to source when application exit
|
|
449
|
+
*/
|
|
450
|
+
persist(): void;
|
|
451
|
+
/**
|
|
452
|
+
* Setup Api
|
|
453
|
+
* @param api Api
|
|
454
|
+
*/
|
|
439
455
|
protected setApi(api: IApi): void;
|
|
440
456
|
/**
|
|
441
457
|
* Api init call
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -18,7 +18,6 @@ export class CoreApp {
|
|
|
18
18
|
* @param name Application name
|
|
19
19
|
*/
|
|
20
20
|
constructor(settings, api, notifier, storage, name) {
|
|
21
|
-
var _a;
|
|
22
21
|
this._authorized = false;
|
|
23
22
|
this._isTryingLogin = false;
|
|
24
23
|
/**
|
|
@@ -36,14 +35,16 @@ export class CoreApp {
|
|
|
36
35
|
/**
|
|
37
36
|
* Passphrase for encryption
|
|
38
37
|
*/
|
|
39
|
-
this.passphrase = '
|
|
38
|
+
this.passphrase = '';
|
|
40
39
|
this.settings = settings;
|
|
41
40
|
this.api = api;
|
|
42
41
|
this.notifier = notifier;
|
|
43
42
|
this.storage = storage;
|
|
44
43
|
this.name = name;
|
|
44
|
+
// Restore
|
|
45
|
+
this.restore();
|
|
45
46
|
// Device id
|
|
46
|
-
this._deviceId =
|
|
47
|
+
this._deviceId = storage.getData(CoreApp.deviceIdField, '');
|
|
47
48
|
this.setApi(api);
|
|
48
49
|
const { currentCulture, currentRegion } = settings;
|
|
49
50
|
this.changeCulture(currentCulture);
|
|
@@ -108,6 +109,38 @@ export class CoreApp {
|
|
|
108
109
|
set authorized(value) {
|
|
109
110
|
this._authorized = value;
|
|
110
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Restore settings from persisted source
|
|
114
|
+
*/
|
|
115
|
+
restore() {
|
|
116
|
+
const passphraseEncrypted = this.storage.getData(CoreApp.devicePassphraseField);
|
|
117
|
+
if (passphraseEncrypted) {
|
|
118
|
+
const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
|
|
119
|
+
if (passphraseDecrypted != null) {
|
|
120
|
+
this.passphrase = passphraseDecrypted;
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Restore
|
|
125
|
+
this.storage.copy([
|
|
126
|
+
CoreApp.deviceIdField,
|
|
127
|
+
CoreApp.serversideDeviceIdField,
|
|
128
|
+
CoreApp.headerTokenField
|
|
129
|
+
], true);
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Persist settings to source when application exit
|
|
134
|
+
*/
|
|
135
|
+
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));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Setup Api
|
|
142
|
+
* @param api Api
|
|
143
|
+
*/
|
|
111
144
|
setApi(api) {
|
|
112
145
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
113
146
|
api.onRequest = (data) => {
|
|
@@ -154,16 +187,10 @@ export class CoreApp {
|
|
|
154
187
|
async initCall(callback) {
|
|
155
188
|
var _a;
|
|
156
189
|
// Passphrase exists?
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (passphraseDecrypted != null) {
|
|
162
|
-
this.passphrase = passphraseDecrypted;
|
|
163
|
-
if (callback)
|
|
164
|
-
callback(true);
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
190
|
+
if (this.passphrase) {
|
|
191
|
+
if (callback)
|
|
192
|
+
callback(true);
|
|
193
|
+
return;
|
|
167
194
|
}
|
|
168
195
|
// Serverside encrypted device id
|
|
169
196
|
const identifier = this.storage.getData(CoreApp.serversideDeviceIdField);
|
|
@@ -225,7 +252,7 @@ export class CoreApp {
|
|
|
225
252
|
return;
|
|
226
253
|
// Update device id and cache it
|
|
227
254
|
this._deviceId = data.deviceId;
|
|
228
|
-
this.storage.setData(CoreApp.deviceIdField, this.
|
|
255
|
+
this.storage.setData(CoreApp.deviceIdField, this._deviceId);
|
|
229
256
|
// Current passphrase
|
|
230
257
|
this.passphrase = passphrase;
|
|
231
258
|
this.storage.setData(CoreApp.devicePassphraseField, this.encrypt(passphrase, this.name));
|
|
@@ -319,7 +346,7 @@ export class CoreApp {
|
|
|
319
346
|
if (regionItem == null || !this.settings.regions.includes(regionId))
|
|
320
347
|
return;
|
|
321
348
|
// Save the id to local storage
|
|
322
|
-
this.storage.
|
|
349
|
+
this.storage.setPersistedData(DomUtils.CountryField, regionId);
|
|
323
350
|
// Set the currency and culture
|
|
324
351
|
this._currency = regionItem.currency;
|
|
325
352
|
this._region = regionId;
|
|
@@ -337,7 +364,7 @@ export class CoreApp {
|
|
|
337
364
|
if (this._culture === name)
|
|
338
365
|
return;
|
|
339
366
|
// Save the cultrue to local storage
|
|
340
|
-
this.storage.
|
|
367
|
+
this.storage.setPersistedData(DomUtils.CultureField, name);
|
|
341
368
|
// Change the API's Content-Language header
|
|
342
369
|
// .net 5 API, UseRequestLocalization, RequestCultureProviders, ContentLanguageHeaderRequestCultureProvider
|
|
343
370
|
this.api.setContentLanguage(name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
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.93",
|
|
58
58
|
"@types/crypto-js": "^4.0.2",
|
|
59
59
|
"crypto-js": "^4.1.1"
|
|
60
60
|
},
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -403,6 +403,11 @@ export interface ICoreApp<
|
|
|
403
403
|
serviceId?: number
|
|
404
404
|
): Promise<IdLabelDto[] | undefined>;
|
|
405
405
|
|
|
406
|
+
/**
|
|
407
|
+
* Persist settings to source when application exit
|
|
408
|
+
*/
|
|
409
|
+
persist(): void;
|
|
410
|
+
|
|
406
411
|
/**
|
|
407
412
|
* Switch organization
|
|
408
413
|
* @param id Organization id
|
|
@@ -591,7 +596,7 @@ export abstract class CoreApp<
|
|
|
591
596
|
/**
|
|
592
597
|
* Passphrase for encryption
|
|
593
598
|
*/
|
|
594
|
-
protected passphrase: string = '
|
|
599
|
+
protected passphrase: string = '';
|
|
595
600
|
|
|
596
601
|
private cachedRefreshToken?: string;
|
|
597
602
|
|
|
@@ -616,8 +621,11 @@ export abstract class CoreApp<
|
|
|
616
621
|
this.storage = storage;
|
|
617
622
|
this.name = name;
|
|
618
623
|
|
|
624
|
+
// Restore
|
|
625
|
+
this.restore();
|
|
626
|
+
|
|
619
627
|
// Device id
|
|
620
|
-
this._deviceId = storage.getData
|
|
628
|
+
this._deviceId = storage.getData(CoreApp.deviceIdField, '');
|
|
621
629
|
|
|
622
630
|
this.setApi(api);
|
|
623
631
|
|
|
@@ -630,6 +638,58 @@ export abstract class CoreApp<
|
|
|
630
638
|
this.setup();
|
|
631
639
|
}
|
|
632
640
|
|
|
641
|
+
/**
|
|
642
|
+
* Restore settings from persisted source
|
|
643
|
+
*/
|
|
644
|
+
protected restore() {
|
|
645
|
+
const passphraseEncrypted = this.storage.getData<string>(
|
|
646
|
+
CoreApp.devicePassphraseField
|
|
647
|
+
);
|
|
648
|
+
if (passphraseEncrypted) {
|
|
649
|
+
const passphraseDecrypted = this.decrypt(
|
|
650
|
+
passphraseEncrypted,
|
|
651
|
+
this.name
|
|
652
|
+
);
|
|
653
|
+
if (passphraseDecrypted != null) {
|
|
654
|
+
this.passphrase = passphraseDecrypted;
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// Restore
|
|
660
|
+
this.storage.copy(
|
|
661
|
+
[
|
|
662
|
+
CoreApp.deviceIdField,
|
|
663
|
+
CoreApp.serversideDeviceIdField,
|
|
664
|
+
CoreApp.headerTokenField
|
|
665
|
+
],
|
|
666
|
+
true
|
|
667
|
+
);
|
|
668
|
+
|
|
669
|
+
return true;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Persist settings to source when application exit
|
|
674
|
+
*/
|
|
675
|
+
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
|
+
);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Setup Api
|
|
691
|
+
* @param api Api
|
|
692
|
+
*/
|
|
633
693
|
protected setApi(api: IApi) {
|
|
634
694
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
635
695
|
api.onRequest = (data) => {
|
|
@@ -679,20 +739,9 @@ export abstract class CoreApp<
|
|
|
679
739
|
*/
|
|
680
740
|
async initCall(callback?: (result: boolean) => void) {
|
|
681
741
|
// Passphrase exists?
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
);
|
|
686
|
-
if (passphraseEncrypted) {
|
|
687
|
-
const passphraseDecrypted = this.decrypt(
|
|
688
|
-
passphraseEncrypted,
|
|
689
|
-
this.name
|
|
690
|
-
);
|
|
691
|
-
if (passphraseDecrypted != null) {
|
|
692
|
-
this.passphrase = passphraseDecrypted;
|
|
693
|
-
if (callback) callback(true);
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
742
|
+
if (this.passphrase) {
|
|
743
|
+
if (callback) callback(true);
|
|
744
|
+
return;
|
|
696
745
|
}
|
|
697
746
|
|
|
698
747
|
// Serverside encrypted device id
|
|
@@ -768,7 +817,7 @@ export abstract class CoreApp<
|
|
|
768
817
|
|
|
769
818
|
// Update device id and cache it
|
|
770
819
|
this._deviceId = data.deviceId;
|
|
771
|
-
this.storage.setData(CoreApp.deviceIdField, this.
|
|
820
|
+
this.storage.setData(CoreApp.deviceIdField, this._deviceId);
|
|
772
821
|
|
|
773
822
|
// Current passphrase
|
|
774
823
|
this.passphrase = passphrase;
|
|
@@ -884,7 +933,7 @@ export abstract class CoreApp<
|
|
|
884
933
|
return;
|
|
885
934
|
|
|
886
935
|
// Save the id to local storage
|
|
887
|
-
this.storage.
|
|
936
|
+
this.storage.setPersistedData(DomUtils.CountryField, regionId);
|
|
888
937
|
|
|
889
938
|
// Set the currency and culture
|
|
890
939
|
this._currency = regionItem.currency;
|
|
@@ -906,7 +955,7 @@ export abstract class CoreApp<
|
|
|
906
955
|
if (this._culture === name) return;
|
|
907
956
|
|
|
908
957
|
// Save the cultrue to local storage
|
|
909
|
-
this.storage.
|
|
958
|
+
this.storage.setPersistedData(DomUtils.CultureField, name);
|
|
910
959
|
|
|
911
960
|
// Change the API's Content-Language header
|
|
912
961
|
// .net 5 API, UseRequestLocalization, RequestCultureProviders, ContentLanguageHeaderRequestCultureProvider
|