@etsoo/appscript 1.2.0 → 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 +42 -14
- package/lib/mjs/app/CoreApp.d.ts +16 -0
- package/lib/mjs/app/CoreApp.js +42 -14
- package/package.json +2 -2
- package/src/app/CoreApp.ts +67 -18
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
|
@@ -38,12 +38,14 @@ class CoreApp {
|
|
|
38
38
|
/**
|
|
39
39
|
* Passphrase for encryption
|
|
40
40
|
*/
|
|
41
|
-
this.passphrase = '
|
|
41
|
+
this.passphrase = '';
|
|
42
42
|
this.settings = settings;
|
|
43
43
|
this.api = api;
|
|
44
44
|
this.notifier = notifier;
|
|
45
45
|
this.storage = storage;
|
|
46
46
|
this.name = name;
|
|
47
|
+
// Restore
|
|
48
|
+
this.restore();
|
|
47
49
|
// Device id
|
|
48
50
|
this._deviceId = storage.getData(CoreApp.deviceIdField, '');
|
|
49
51
|
this.setApi(api);
|
|
@@ -110,6 +112,38 @@ class CoreApp {
|
|
|
110
112
|
set authorized(value) {
|
|
111
113
|
this._authorized = value;
|
|
112
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
|
+
*/
|
|
113
147
|
setApi(api) {
|
|
114
148
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
115
149
|
api.onRequest = (data) => {
|
|
@@ -156,16 +190,10 @@ class CoreApp {
|
|
|
156
190
|
async initCall(callback) {
|
|
157
191
|
var _a;
|
|
158
192
|
// Passphrase exists?
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (passphraseDecrypted != null) {
|
|
164
|
-
this.passphrase = passphraseDecrypted;
|
|
165
|
-
if (callback)
|
|
166
|
-
callback(true);
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
193
|
+
if (this.passphrase) {
|
|
194
|
+
if (callback)
|
|
195
|
+
callback(true);
|
|
196
|
+
return;
|
|
169
197
|
}
|
|
170
198
|
// Serverside encrypted device id
|
|
171
199
|
const identifier = this.storage.getData(CoreApp.serversideDeviceIdField);
|
|
@@ -175,7 +203,7 @@ class CoreApp {
|
|
|
175
203
|
const data = {
|
|
176
204
|
timestamp,
|
|
177
205
|
identifier,
|
|
178
|
-
deviceId: this.deviceId
|
|
206
|
+
deviceId: this.deviceId ? this.deviceId : undefined
|
|
179
207
|
};
|
|
180
208
|
const result = await this.apiInitCall(data);
|
|
181
209
|
if (result == null) {
|
|
@@ -321,7 +349,7 @@ class CoreApp {
|
|
|
321
349
|
if (regionItem == null || !this.settings.regions.includes(regionId))
|
|
322
350
|
return;
|
|
323
351
|
// Save the id to local storage
|
|
324
|
-
this.storage.
|
|
352
|
+
this.storage.setPersistedData(shared_1.DomUtils.CountryField, regionId);
|
|
325
353
|
// Set the currency and culture
|
|
326
354
|
this._currency = regionItem.currency;
|
|
327
355
|
this._region = regionId;
|
|
@@ -339,7 +367,7 @@ class CoreApp {
|
|
|
339
367
|
if (this._culture === name)
|
|
340
368
|
return;
|
|
341
369
|
// Save the cultrue to local storage
|
|
342
|
-
this.storage.
|
|
370
|
+
this.storage.setPersistedData(shared_1.DomUtils.CultureField, name);
|
|
343
371
|
// Change the API's Content-Language header
|
|
344
372
|
// .net 5 API, UseRequestLocalization, RequestCultureProviders, ContentLanguageHeaderRequestCultureProvider
|
|
345
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
|
@@ -35,12 +35,14 @@ export class CoreApp {
|
|
|
35
35
|
/**
|
|
36
36
|
* Passphrase for encryption
|
|
37
37
|
*/
|
|
38
|
-
this.passphrase = '
|
|
38
|
+
this.passphrase = '';
|
|
39
39
|
this.settings = settings;
|
|
40
40
|
this.api = api;
|
|
41
41
|
this.notifier = notifier;
|
|
42
42
|
this.storage = storage;
|
|
43
43
|
this.name = name;
|
|
44
|
+
// Restore
|
|
45
|
+
this.restore();
|
|
44
46
|
// Device id
|
|
45
47
|
this._deviceId = storage.getData(CoreApp.deviceIdField, '');
|
|
46
48
|
this.setApi(api);
|
|
@@ -107,6 +109,38 @@ export class CoreApp {
|
|
|
107
109
|
set authorized(value) {
|
|
108
110
|
this._authorized = value;
|
|
109
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
|
+
*/
|
|
110
144
|
setApi(api) {
|
|
111
145
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
112
146
|
api.onRequest = (data) => {
|
|
@@ -153,16 +187,10 @@ export class CoreApp {
|
|
|
153
187
|
async initCall(callback) {
|
|
154
188
|
var _a;
|
|
155
189
|
// Passphrase exists?
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (passphraseDecrypted != null) {
|
|
161
|
-
this.passphrase = passphraseDecrypted;
|
|
162
|
-
if (callback)
|
|
163
|
-
callback(true);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
190
|
+
if (this.passphrase) {
|
|
191
|
+
if (callback)
|
|
192
|
+
callback(true);
|
|
193
|
+
return;
|
|
166
194
|
}
|
|
167
195
|
// Serverside encrypted device id
|
|
168
196
|
const identifier = this.storage.getData(CoreApp.serversideDeviceIdField);
|
|
@@ -172,7 +200,7 @@ export class CoreApp {
|
|
|
172
200
|
const data = {
|
|
173
201
|
timestamp,
|
|
174
202
|
identifier,
|
|
175
|
-
deviceId: this.deviceId
|
|
203
|
+
deviceId: this.deviceId ? this.deviceId : undefined
|
|
176
204
|
};
|
|
177
205
|
const result = await this.apiInitCall(data);
|
|
178
206
|
if (result == null) {
|
|
@@ -318,7 +346,7 @@ export class CoreApp {
|
|
|
318
346
|
if (regionItem == null || !this.settings.regions.includes(regionId))
|
|
319
347
|
return;
|
|
320
348
|
// Save the id to local storage
|
|
321
|
-
this.storage.
|
|
349
|
+
this.storage.setPersistedData(DomUtils.CountryField, regionId);
|
|
322
350
|
// Set the currency and culture
|
|
323
351
|
this._currency = regionItem.currency;
|
|
324
352
|
this._region = regionId;
|
|
@@ -336,7 +364,7 @@ export class CoreApp {
|
|
|
336
364
|
if (this._culture === name)
|
|
337
365
|
return;
|
|
338
366
|
// Save the cultrue to local storage
|
|
339
|
-
this.storage.
|
|
367
|
+
this.storage.setPersistedData(DomUtils.CultureField, name);
|
|
340
368
|
// Change the API's Content-Language header
|
|
341
369
|
// .net 5 API, UseRequestLocalization, RequestCultureProviders, ContentLanguageHeaderRequestCultureProvider
|
|
342
370
|
this.api.setContentLanguage(name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.2.
|
|
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,6 +621,9 @@ 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
628
|
this._deviceId = storage.getData(CoreApp.deviceIdField, '');
|
|
621
629
|
|
|
@@ -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
|
|
@@ -707,7 +756,7 @@ export abstract class CoreApp<
|
|
|
707
756
|
const data: InitCallDto = {
|
|
708
757
|
timestamp,
|
|
709
758
|
identifier,
|
|
710
|
-
deviceId: this.deviceId
|
|
759
|
+
deviceId: this.deviceId ? this.deviceId : undefined
|
|
711
760
|
};
|
|
712
761
|
|
|
713
762
|
const result = await this.apiInitCall(data);
|
|
@@ -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
|