@etsoo/appscript 1.1.86 → 1.1.90
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 +26 -8
- package/lib/cjs/app/CoreApp.js +44 -9
- package/lib/mjs/app/CoreApp.d.ts +26 -8
- package/lib/mjs/app/CoreApp.js +44 -9
- package/package.json +1 -1
- package/src/app/CoreApp.ts +76 -26
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -119,6 +119,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
119
119
|
* @param culture New culture definition
|
|
120
120
|
*/
|
|
121
121
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
122
|
+
/**
|
|
123
|
+
* Clear cache data
|
|
124
|
+
*/
|
|
125
|
+
clearCacheData(): void;
|
|
122
126
|
/**
|
|
123
127
|
* Clear cached token
|
|
124
128
|
*/
|
|
@@ -276,9 +280,8 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
276
280
|
refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
|
|
277
281
|
/**
|
|
278
282
|
* Signout
|
|
279
|
-
* @param apiUrl Signout API URL
|
|
280
283
|
*/
|
|
281
|
-
signout(
|
|
284
|
+
signout(): Promise<void>;
|
|
282
285
|
/**
|
|
283
286
|
* Get organization list
|
|
284
287
|
* @param items Max items
|
|
@@ -288,9 +291,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
288
291
|
orgList(items?: number, serviceId?: number): Promise<IdLabelDto[] | undefined>;
|
|
289
292
|
/**
|
|
290
293
|
* Switch organization
|
|
291
|
-
* @param
|
|
294
|
+
* @param id Organization id
|
|
295
|
+
* @param serviceId Service id
|
|
292
296
|
*/
|
|
293
|
-
switchOrg(
|
|
297
|
+
switchOrg(id: number, serviceId?: number): Promise<boolean | undefined>;
|
|
294
298
|
/**
|
|
295
299
|
* Go to the login page
|
|
296
300
|
*/
|
|
@@ -418,11 +422,15 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
418
422
|
/**
|
|
419
423
|
* Device id field name
|
|
420
424
|
*/
|
|
421
|
-
|
|
425
|
+
private readonly deviceIdField;
|
|
426
|
+
/**
|
|
427
|
+
* Device passphrase field name
|
|
428
|
+
*/
|
|
429
|
+
private readonly devicePassphraseField;
|
|
422
430
|
/**
|
|
423
431
|
* Device id update time field name
|
|
424
432
|
*/
|
|
425
|
-
|
|
433
|
+
private readonly deviceIdUpdateTimeField;
|
|
426
434
|
/**
|
|
427
435
|
* Init call Api URL
|
|
428
436
|
*/
|
|
@@ -441,6 +449,11 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
441
449
|
*/
|
|
442
450
|
protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, name: string);
|
|
443
451
|
protected setApi(api: IApi): void;
|
|
452
|
+
/**
|
|
453
|
+
* Setup device
|
|
454
|
+
* @returns Device id
|
|
455
|
+
*/
|
|
456
|
+
protected setupDevice(): string;
|
|
444
457
|
/**
|
|
445
458
|
* Api init call
|
|
446
459
|
* @param data Data
|
|
@@ -490,6 +503,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
490
503
|
* @param culture New culture definition
|
|
491
504
|
*/
|
|
492
505
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
506
|
+
/**
|
|
507
|
+
* Clear cache data
|
|
508
|
+
*/
|
|
509
|
+
clearCacheData(): void;
|
|
493
510
|
/**
|
|
494
511
|
* Clear cached token
|
|
495
512
|
*/
|
|
@@ -661,7 +678,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
661
678
|
* Signout
|
|
662
679
|
* @param apiUrl Signout API URL
|
|
663
680
|
*/
|
|
664
|
-
signout(
|
|
681
|
+
signout(): Promise<void>;
|
|
665
682
|
/**
|
|
666
683
|
* Get organization list
|
|
667
684
|
* @param items Max items
|
|
@@ -672,8 +689,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
672
689
|
/**
|
|
673
690
|
* Switch organization
|
|
674
691
|
* @param id Organization id
|
|
692
|
+
* @param serviceId Service id
|
|
675
693
|
*/
|
|
676
|
-
switchOrg(id: number): Promise<boolean | undefined>;
|
|
694
|
+
switchOrg(id: number, serviceId?: number): Promise<boolean | undefined>;
|
|
677
695
|
/**
|
|
678
696
|
* Go to the login page
|
|
679
697
|
*/
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -43,6 +43,10 @@ class CoreApp {
|
|
|
43
43
|
* Device id field name
|
|
44
44
|
*/
|
|
45
45
|
this.deviceIdField = 'SmartERPDeviceId';
|
|
46
|
+
/**
|
|
47
|
+
* Device passphrase field name
|
|
48
|
+
*/
|
|
49
|
+
this.devicePassphraseField = 'SmartERPDevicePassphrase';
|
|
46
50
|
/**
|
|
47
51
|
* Device id update time field name
|
|
48
52
|
*/
|
|
@@ -59,7 +63,7 @@ class CoreApp {
|
|
|
59
63
|
this.api = api;
|
|
60
64
|
this.notifier = notifier;
|
|
61
65
|
this.name = name;
|
|
62
|
-
this.deviceId =
|
|
66
|
+
this.deviceId = this.setupDevice();
|
|
63
67
|
this.setApi(api);
|
|
64
68
|
const { currentCulture, currentRegion } = settings;
|
|
65
69
|
this.changeCulture(currentCulture);
|
|
@@ -157,6 +161,25 @@ class CoreApp {
|
|
|
157
161
|
}
|
|
158
162
|
};
|
|
159
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Setup device
|
|
166
|
+
* @returns Device id
|
|
167
|
+
*/
|
|
168
|
+
setupDevice() {
|
|
169
|
+
const deviceId = shared_1.StorageUtils.getLocalData(this.deviceIdField);
|
|
170
|
+
if (deviceId != null && deviceId !== '') {
|
|
171
|
+
const passphraseEncrypted = shared_1.StorageUtils.getLocalData(this.devicePassphraseField);
|
|
172
|
+
if (passphraseEncrypted != null && passphraseEncrypted !== '') {
|
|
173
|
+
const timestamp = this.getDeviceUpdateTime();
|
|
174
|
+
if (timestamp > 0) {
|
|
175
|
+
const passphraseDecrypted = this.decrypt(passphraseEncrypted, timestamp.toString());
|
|
176
|
+
if (passphraseDecrypted != null)
|
|
177
|
+
this.passphrase = passphraseDecrypted;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return deviceId !== null && deviceId !== void 0 ? deviceId : '';
|
|
182
|
+
}
|
|
160
183
|
/**
|
|
161
184
|
* Api init call
|
|
162
185
|
* @param data Data
|
|
@@ -248,6 +271,7 @@ class CoreApp {
|
|
|
248
271
|
// Update device id and cache it
|
|
249
272
|
this.deviceId = data.deviceId;
|
|
250
273
|
shared_1.StorageUtils.setLocalData(this.deviceIdField, this.deviceId);
|
|
274
|
+
shared_1.StorageUtils.setLocalData(this.devicePassphraseField, data.passphrase);
|
|
251
275
|
shared_1.StorageUtils.setLocalData(this.deviceIdUpdateTimeField, timestamp);
|
|
252
276
|
// Current passphrase
|
|
253
277
|
this.passphrase = passphrase;
|
|
@@ -257,8 +281,8 @@ class CoreApp {
|
|
|
257
281
|
// Update
|
|
258
282
|
const fields = this.initCallUpdateFields();
|
|
259
283
|
for (const field of fields) {
|
|
260
|
-
const currentValue = shared_1.StorageUtils.getLocalData(field
|
|
261
|
-
if (currentValue === '')
|
|
284
|
+
const currentValue = shared_1.StorageUtils.getLocalData(field);
|
|
285
|
+
if (currentValue == null || currentValue === '')
|
|
262
286
|
continue;
|
|
263
287
|
const enhanced = currentValue.indexOf('!') >= 8;
|
|
264
288
|
let newValueSource = null;
|
|
@@ -374,6 +398,16 @@ class CoreApp {
|
|
|
374
398
|
region.name = AddressUtils_1.AddressUtils.getRegionLabel(id, this.labelDelegate);
|
|
375
399
|
});
|
|
376
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Clear cache data
|
|
403
|
+
*/
|
|
404
|
+
clearCacheData() {
|
|
405
|
+
shared_1.StorageUtils.setLocalData(this.serversideDeviceIdField, undefined);
|
|
406
|
+
shared_1.StorageUtils.setLocalData(this.deviceIdField, undefined);
|
|
407
|
+
shared_1.StorageUtils.setLocalData(this.devicePassphraseField, undefined);
|
|
408
|
+
shared_1.StorageUtils.setLocalData(this.deviceIdUpdateTimeField, undefined);
|
|
409
|
+
shared_1.StorageUtils.setLocalData(this.headerTokenField, undefined);
|
|
410
|
+
}
|
|
377
411
|
/**
|
|
378
412
|
* Clear cached token
|
|
379
413
|
*/
|
|
@@ -756,8 +790,8 @@ class CoreApp {
|
|
|
756
790
|
* Signout
|
|
757
791
|
* @param apiUrl Signout API URL
|
|
758
792
|
*/
|
|
759
|
-
async signout(
|
|
760
|
-
await this.api.put(
|
|
793
|
+
async signout() {
|
|
794
|
+
await this.api.put('User/Signout', { deviceId: this.deviceId }, {
|
|
761
795
|
onError: (error) => {
|
|
762
796
|
console.log(error);
|
|
763
797
|
// Prevent further processing
|
|
@@ -784,10 +818,11 @@ class CoreApp {
|
|
|
784
818
|
/**
|
|
785
819
|
* Switch organization
|
|
786
820
|
* @param id Organization id
|
|
821
|
+
* @param serviceId Service id
|
|
787
822
|
*/
|
|
788
|
-
async switchOrg(id) {
|
|
789
|
-
const api = `Organization/Switch
|
|
790
|
-
const result = await this.api.put(api);
|
|
823
|
+
async switchOrg(id, serviceId) {
|
|
824
|
+
const api = `Organization/Switch`;
|
|
825
|
+
const result = await this.api.put(api, { id, serviceId });
|
|
791
826
|
if (result)
|
|
792
827
|
return await this.refreshToken();
|
|
793
828
|
return result;
|
|
@@ -845,7 +880,7 @@ class CoreApp {
|
|
|
845
880
|
this.authorize(user.token, refreshToken);
|
|
846
881
|
}
|
|
847
882
|
else {
|
|
848
|
-
this.cachedRefreshToken = refreshToken;
|
|
883
|
+
this.cachedRefreshToken = this.encrypt(refreshToken);
|
|
849
884
|
this.authorize(user.token, undefined);
|
|
850
885
|
}
|
|
851
886
|
}
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -119,6 +119,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
119
119
|
* @param culture New culture definition
|
|
120
120
|
*/
|
|
121
121
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
122
|
+
/**
|
|
123
|
+
* Clear cache data
|
|
124
|
+
*/
|
|
125
|
+
clearCacheData(): void;
|
|
122
126
|
/**
|
|
123
127
|
* Clear cached token
|
|
124
128
|
*/
|
|
@@ -276,9 +280,8 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
276
280
|
refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
|
|
277
281
|
/**
|
|
278
282
|
* Signout
|
|
279
|
-
* @param apiUrl Signout API URL
|
|
280
283
|
*/
|
|
281
|
-
signout(
|
|
284
|
+
signout(): Promise<void>;
|
|
282
285
|
/**
|
|
283
286
|
* Get organization list
|
|
284
287
|
* @param items Max items
|
|
@@ -288,9 +291,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
288
291
|
orgList(items?: number, serviceId?: number): Promise<IdLabelDto[] | undefined>;
|
|
289
292
|
/**
|
|
290
293
|
* Switch organization
|
|
291
|
-
* @param
|
|
294
|
+
* @param id Organization id
|
|
295
|
+
* @param serviceId Service id
|
|
292
296
|
*/
|
|
293
|
-
switchOrg(
|
|
297
|
+
switchOrg(id: number, serviceId?: number): Promise<boolean | undefined>;
|
|
294
298
|
/**
|
|
295
299
|
* Go to the login page
|
|
296
300
|
*/
|
|
@@ -418,11 +422,15 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
418
422
|
/**
|
|
419
423
|
* Device id field name
|
|
420
424
|
*/
|
|
421
|
-
|
|
425
|
+
private readonly deviceIdField;
|
|
426
|
+
/**
|
|
427
|
+
* Device passphrase field name
|
|
428
|
+
*/
|
|
429
|
+
private readonly devicePassphraseField;
|
|
422
430
|
/**
|
|
423
431
|
* Device id update time field name
|
|
424
432
|
*/
|
|
425
|
-
|
|
433
|
+
private readonly deviceIdUpdateTimeField;
|
|
426
434
|
/**
|
|
427
435
|
* Init call Api URL
|
|
428
436
|
*/
|
|
@@ -441,6 +449,11 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
441
449
|
*/
|
|
442
450
|
protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, name: string);
|
|
443
451
|
protected setApi(api: IApi): void;
|
|
452
|
+
/**
|
|
453
|
+
* Setup device
|
|
454
|
+
* @returns Device id
|
|
455
|
+
*/
|
|
456
|
+
protected setupDevice(): string;
|
|
444
457
|
/**
|
|
445
458
|
* Api init call
|
|
446
459
|
* @param data Data
|
|
@@ -490,6 +503,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
490
503
|
* @param culture New culture definition
|
|
491
504
|
*/
|
|
492
505
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
506
|
+
/**
|
|
507
|
+
* Clear cache data
|
|
508
|
+
*/
|
|
509
|
+
clearCacheData(): void;
|
|
493
510
|
/**
|
|
494
511
|
* Clear cached token
|
|
495
512
|
*/
|
|
@@ -661,7 +678,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
661
678
|
* Signout
|
|
662
679
|
* @param apiUrl Signout API URL
|
|
663
680
|
*/
|
|
664
|
-
signout(
|
|
681
|
+
signout(): Promise<void>;
|
|
665
682
|
/**
|
|
666
683
|
* Get organization list
|
|
667
684
|
* @param items Max items
|
|
@@ -672,8 +689,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
672
689
|
/**
|
|
673
690
|
* Switch organization
|
|
674
691
|
* @param id Organization id
|
|
692
|
+
* @param serviceId Service id
|
|
675
693
|
*/
|
|
676
|
-
switchOrg(id: number): Promise<boolean | undefined>;
|
|
694
|
+
switchOrg(id: number, serviceId?: number): Promise<boolean | undefined>;
|
|
677
695
|
/**
|
|
678
696
|
* Go to the login page
|
|
679
697
|
*/
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -40,6 +40,10 @@ export class CoreApp {
|
|
|
40
40
|
* Device id field name
|
|
41
41
|
*/
|
|
42
42
|
this.deviceIdField = 'SmartERPDeviceId';
|
|
43
|
+
/**
|
|
44
|
+
* Device passphrase field name
|
|
45
|
+
*/
|
|
46
|
+
this.devicePassphraseField = 'SmartERPDevicePassphrase';
|
|
43
47
|
/**
|
|
44
48
|
* Device id update time field name
|
|
45
49
|
*/
|
|
@@ -56,7 +60,7 @@ export class CoreApp {
|
|
|
56
60
|
this.api = api;
|
|
57
61
|
this.notifier = notifier;
|
|
58
62
|
this.name = name;
|
|
59
|
-
this.deviceId =
|
|
63
|
+
this.deviceId = this.setupDevice();
|
|
60
64
|
this.setApi(api);
|
|
61
65
|
const { currentCulture, currentRegion } = settings;
|
|
62
66
|
this.changeCulture(currentCulture);
|
|
@@ -154,6 +158,25 @@ export class CoreApp {
|
|
|
154
158
|
}
|
|
155
159
|
};
|
|
156
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Setup device
|
|
163
|
+
* @returns Device id
|
|
164
|
+
*/
|
|
165
|
+
setupDevice() {
|
|
166
|
+
const deviceId = StorageUtils.getLocalData(this.deviceIdField);
|
|
167
|
+
if (deviceId != null && deviceId !== '') {
|
|
168
|
+
const passphraseEncrypted = StorageUtils.getLocalData(this.devicePassphraseField);
|
|
169
|
+
if (passphraseEncrypted != null && passphraseEncrypted !== '') {
|
|
170
|
+
const timestamp = this.getDeviceUpdateTime();
|
|
171
|
+
if (timestamp > 0) {
|
|
172
|
+
const passphraseDecrypted = this.decrypt(passphraseEncrypted, timestamp.toString());
|
|
173
|
+
if (passphraseDecrypted != null)
|
|
174
|
+
this.passphrase = passphraseDecrypted;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return deviceId !== null && deviceId !== void 0 ? deviceId : '';
|
|
179
|
+
}
|
|
157
180
|
/**
|
|
158
181
|
* Api init call
|
|
159
182
|
* @param data Data
|
|
@@ -245,6 +268,7 @@ export class CoreApp {
|
|
|
245
268
|
// Update device id and cache it
|
|
246
269
|
this.deviceId = data.deviceId;
|
|
247
270
|
StorageUtils.setLocalData(this.deviceIdField, this.deviceId);
|
|
271
|
+
StorageUtils.setLocalData(this.devicePassphraseField, data.passphrase);
|
|
248
272
|
StorageUtils.setLocalData(this.deviceIdUpdateTimeField, timestamp);
|
|
249
273
|
// Current passphrase
|
|
250
274
|
this.passphrase = passphrase;
|
|
@@ -254,8 +278,8 @@ export class CoreApp {
|
|
|
254
278
|
// Update
|
|
255
279
|
const fields = this.initCallUpdateFields();
|
|
256
280
|
for (const field of fields) {
|
|
257
|
-
const currentValue = StorageUtils.getLocalData(field
|
|
258
|
-
if (currentValue === '')
|
|
281
|
+
const currentValue = StorageUtils.getLocalData(field);
|
|
282
|
+
if (currentValue == null || currentValue === '')
|
|
259
283
|
continue;
|
|
260
284
|
const enhanced = currentValue.indexOf('!') >= 8;
|
|
261
285
|
let newValueSource = null;
|
|
@@ -371,6 +395,16 @@ export class CoreApp {
|
|
|
371
395
|
region.name = AddressUtils.getRegionLabel(id, this.labelDelegate);
|
|
372
396
|
});
|
|
373
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Clear cache data
|
|
400
|
+
*/
|
|
401
|
+
clearCacheData() {
|
|
402
|
+
StorageUtils.setLocalData(this.serversideDeviceIdField, undefined);
|
|
403
|
+
StorageUtils.setLocalData(this.deviceIdField, undefined);
|
|
404
|
+
StorageUtils.setLocalData(this.devicePassphraseField, undefined);
|
|
405
|
+
StorageUtils.setLocalData(this.deviceIdUpdateTimeField, undefined);
|
|
406
|
+
StorageUtils.setLocalData(this.headerTokenField, undefined);
|
|
407
|
+
}
|
|
374
408
|
/**
|
|
375
409
|
* Clear cached token
|
|
376
410
|
*/
|
|
@@ -753,8 +787,8 @@ export class CoreApp {
|
|
|
753
787
|
* Signout
|
|
754
788
|
* @param apiUrl Signout API URL
|
|
755
789
|
*/
|
|
756
|
-
async signout(
|
|
757
|
-
await this.api.put(
|
|
790
|
+
async signout() {
|
|
791
|
+
await this.api.put('User/Signout', { deviceId: this.deviceId }, {
|
|
758
792
|
onError: (error) => {
|
|
759
793
|
console.log(error);
|
|
760
794
|
// Prevent further processing
|
|
@@ -781,10 +815,11 @@ export class CoreApp {
|
|
|
781
815
|
/**
|
|
782
816
|
* Switch organization
|
|
783
817
|
* @param id Organization id
|
|
818
|
+
* @param serviceId Service id
|
|
784
819
|
*/
|
|
785
|
-
async switchOrg(id) {
|
|
786
|
-
const api = `Organization/Switch
|
|
787
|
-
const result = await this.api.put(api);
|
|
820
|
+
async switchOrg(id, serviceId) {
|
|
821
|
+
const api = `Organization/Switch`;
|
|
822
|
+
const result = await this.api.put(api, { id, serviceId });
|
|
788
823
|
if (result)
|
|
789
824
|
return await this.refreshToken();
|
|
790
825
|
return result;
|
|
@@ -842,7 +877,7 @@ export class CoreApp {
|
|
|
842
877
|
this.authorize(user.token, refreshToken);
|
|
843
878
|
}
|
|
844
879
|
else {
|
|
845
|
-
this.cachedRefreshToken = refreshToken;
|
|
880
|
+
this.cachedRefreshToken = this.encrypt(refreshToken);
|
|
846
881
|
this.authorize(user.token, undefined);
|
|
847
882
|
}
|
|
848
883
|
}
|
package/package.json
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -178,6 +178,11 @@ export interface ICoreApp<
|
|
|
178
178
|
*/
|
|
179
179
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
180
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Clear cache data
|
|
183
|
+
*/
|
|
184
|
+
clearCacheData(): void;
|
|
185
|
+
|
|
181
186
|
/**
|
|
182
187
|
* Clear cached token
|
|
183
188
|
*/
|
|
@@ -379,9 +384,8 @@ export interface ICoreApp<
|
|
|
379
384
|
|
|
380
385
|
/**
|
|
381
386
|
* Signout
|
|
382
|
-
* @param apiUrl Signout API URL
|
|
383
387
|
*/
|
|
384
|
-
signout(
|
|
388
|
+
signout(): Promise<void>;
|
|
385
389
|
|
|
386
390
|
/**
|
|
387
391
|
* Get organization list
|
|
@@ -396,9 +400,10 @@ export interface ICoreApp<
|
|
|
396
400
|
|
|
397
401
|
/**
|
|
398
402
|
* Switch organization
|
|
399
|
-
* @param
|
|
403
|
+
* @param id Organization id
|
|
404
|
+
* @param serviceId Service id
|
|
400
405
|
*/
|
|
401
|
-
switchOrg(
|
|
406
|
+
switchOrg(id: number, serviceId?: number): Promise<boolean | undefined>;
|
|
402
407
|
|
|
403
408
|
/**
|
|
404
409
|
* Go to the login page
|
|
@@ -584,12 +589,17 @@ export abstract class CoreApp<
|
|
|
584
589
|
/**
|
|
585
590
|
* Device id field name
|
|
586
591
|
*/
|
|
587
|
-
|
|
592
|
+
private readonly deviceIdField: string = 'SmartERPDeviceId';
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Device passphrase field name
|
|
596
|
+
*/
|
|
597
|
+
private readonly devicePassphraseField: string = 'SmartERPDevicePassphrase';
|
|
588
598
|
|
|
589
599
|
/**
|
|
590
600
|
* Device id update time field name
|
|
591
601
|
*/
|
|
592
|
-
|
|
602
|
+
private readonly deviceIdUpdateTimeField: string =
|
|
593
603
|
'SmartERPDeviceIdUpdateTime';
|
|
594
604
|
|
|
595
605
|
/**
|
|
@@ -622,10 +632,7 @@ export abstract class CoreApp<
|
|
|
622
632
|
this.notifier = notifier;
|
|
623
633
|
this.name = name;
|
|
624
634
|
|
|
625
|
-
this.deviceId =
|
|
626
|
-
this.deviceIdField,
|
|
627
|
-
''
|
|
628
|
-
);
|
|
635
|
+
this.deviceId = this.setupDevice();
|
|
629
636
|
|
|
630
637
|
this.setApi(api);
|
|
631
638
|
|
|
@@ -671,6 +678,33 @@ export abstract class CoreApp<
|
|
|
671
678
|
};
|
|
672
679
|
}
|
|
673
680
|
|
|
681
|
+
/**
|
|
682
|
+
* Setup device
|
|
683
|
+
* @returns Device id
|
|
684
|
+
*/
|
|
685
|
+
protected setupDevice() {
|
|
686
|
+
const deviceId = StorageUtils.getLocalData<string>(this.deviceIdField);
|
|
687
|
+
|
|
688
|
+
if (deviceId != null && deviceId !== '') {
|
|
689
|
+
const passphraseEncrypted = StorageUtils.getLocalData<string>(
|
|
690
|
+
this.devicePassphraseField
|
|
691
|
+
);
|
|
692
|
+
if (passphraseEncrypted != null && passphraseEncrypted !== '') {
|
|
693
|
+
const timestamp = this.getDeviceUpdateTime();
|
|
694
|
+
if (timestamp > 0) {
|
|
695
|
+
const passphraseDecrypted = this.decrypt(
|
|
696
|
+
passphraseEncrypted,
|
|
697
|
+
timestamp.toString()
|
|
698
|
+
);
|
|
699
|
+
if (passphraseDecrypted != null)
|
|
700
|
+
this.passphrase = passphraseDecrypted;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
return deviceId ?? '';
|
|
706
|
+
}
|
|
707
|
+
|
|
674
708
|
/**
|
|
675
709
|
* Api init call
|
|
676
710
|
* @param data Data
|
|
@@ -776,6 +810,7 @@ export abstract class CoreApp<
|
|
|
776
810
|
// Update device id and cache it
|
|
777
811
|
this.deviceId = data.deviceId;
|
|
778
812
|
StorageUtils.setLocalData(this.deviceIdField, this.deviceId);
|
|
813
|
+
StorageUtils.setLocalData(this.devicePassphraseField, data.passphrase);
|
|
779
814
|
StorageUtils.setLocalData(this.deviceIdUpdateTimeField, timestamp);
|
|
780
815
|
|
|
781
816
|
// Current passphrase
|
|
@@ -791,11 +826,8 @@ export abstract class CoreApp<
|
|
|
791
826
|
// Update
|
|
792
827
|
const fields = this.initCallUpdateFields();
|
|
793
828
|
for (const field of fields) {
|
|
794
|
-
const currentValue = StorageUtils.getLocalData<string>(
|
|
795
|
-
|
|
796
|
-
''
|
|
797
|
-
);
|
|
798
|
-
if (currentValue === '') continue;
|
|
829
|
+
const currentValue = StorageUtils.getLocalData<string>(field);
|
|
830
|
+
if (currentValue == null || currentValue === '') continue;
|
|
799
831
|
|
|
800
832
|
const enhanced = currentValue.indexOf('!') >= 8;
|
|
801
833
|
let newValueSource = null;
|
|
@@ -936,6 +968,19 @@ export abstract class CoreApp<
|
|
|
936
968
|
});
|
|
937
969
|
}
|
|
938
970
|
|
|
971
|
+
/**
|
|
972
|
+
* Clear cache data
|
|
973
|
+
*/
|
|
974
|
+
clearCacheData() {
|
|
975
|
+
StorageUtils.setLocalData(this.serversideDeviceIdField, undefined);
|
|
976
|
+
|
|
977
|
+
StorageUtils.setLocalData(this.deviceIdField, undefined);
|
|
978
|
+
StorageUtils.setLocalData(this.devicePassphraseField, undefined);
|
|
979
|
+
StorageUtils.setLocalData(this.deviceIdUpdateTimeField, undefined);
|
|
980
|
+
|
|
981
|
+
StorageUtils.setLocalData(this.headerTokenField, undefined);
|
|
982
|
+
}
|
|
983
|
+
|
|
939
984
|
/**
|
|
940
985
|
* Clear cached token
|
|
941
986
|
*/
|
|
@@ -1390,14 +1435,18 @@ export abstract class CoreApp<
|
|
|
1390
1435
|
* Signout
|
|
1391
1436
|
* @param apiUrl Signout API URL
|
|
1392
1437
|
*/
|
|
1393
|
-
async signout(
|
|
1394
|
-
await this.api.put<boolean>(
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1438
|
+
async signout() {
|
|
1439
|
+
await this.api.put<boolean>(
|
|
1440
|
+
'User/Signout',
|
|
1441
|
+
{ deviceId: this.deviceId },
|
|
1442
|
+
{
|
|
1443
|
+
onError: (error) => {
|
|
1444
|
+
console.log(error);
|
|
1445
|
+
// Prevent further processing
|
|
1446
|
+
return false;
|
|
1447
|
+
}
|
|
1399
1448
|
}
|
|
1400
|
-
|
|
1449
|
+
);
|
|
1401
1450
|
|
|
1402
1451
|
// Clear
|
|
1403
1452
|
this.userLogout();
|
|
@@ -1426,10 +1475,11 @@ export abstract class CoreApp<
|
|
|
1426
1475
|
/**
|
|
1427
1476
|
* Switch organization
|
|
1428
1477
|
* @param id Organization id
|
|
1478
|
+
* @param serviceId Service id
|
|
1429
1479
|
*/
|
|
1430
|
-
async switchOrg(id: number) {
|
|
1431
|
-
const api = `Organization/Switch
|
|
1432
|
-
const result = await this.api.put<boolean>(api);
|
|
1480
|
+
async switchOrg(id: number, serviceId?: number) {
|
|
1481
|
+
const api = `Organization/Switch`;
|
|
1482
|
+
const result = await this.api.put<boolean>(api, { id, serviceId });
|
|
1433
1483
|
if (result) return await this.refreshToken();
|
|
1434
1484
|
return result;
|
|
1435
1485
|
}
|
|
@@ -1492,7 +1542,7 @@ export abstract class CoreApp<
|
|
|
1492
1542
|
if (keep) {
|
|
1493
1543
|
this.authorize(user.token, refreshToken);
|
|
1494
1544
|
} else {
|
|
1495
|
-
this.cachedRefreshToken = refreshToken;
|
|
1545
|
+
this.cachedRefreshToken = this.encrypt(refreshToken);
|
|
1496
1546
|
this.authorize(user.token, undefined);
|
|
1497
1547
|
}
|
|
1498
1548
|
}
|