@etsoo/appscript 1.2.42 → 1.2.46

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.
@@ -312,6 +312,11 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
312
312
  * Persist settings to source when application exit
313
313
  */
314
314
  persist(): void;
315
+ /**
316
+ * Redirect to the Url
317
+ * @param url Url
318
+ */
319
+ redirectTo(url: string): void;
315
320
  /**
316
321
  * Switch organization
317
322
  * @param id Organization id
@@ -470,6 +475,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
470
475
  * Persist settings to source when application exit
471
476
  */
472
477
  persist(): void;
478
+ /**
479
+ * Add app name as identifier
480
+ * @param field Field
481
+ * @returns Result
482
+ */
483
+ protected addIdentifier(field: string): string;
473
484
  /**
474
485
  * Setup Api
475
486
  * @param api Api
@@ -684,6 +695,11 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
684
695
  * Callback where exit a page
685
696
  */
686
697
  pageExit(): void;
698
+ /**
699
+ * Redirect to the Url
700
+ * @param url Url
701
+ */
702
+ redirectTo(url: string): void;
687
703
  /**
688
704
  * Refresh countdown
689
705
  * @param seconds Seconds
@@ -119,9 +119,9 @@ class CoreApp {
119
119
  get persistedFields() {
120
120
  return [
121
121
  CoreApp.deviceIdField,
122
- CoreApp.devicePassphraseField,
122
+ this.addIdentifier(CoreApp.devicePassphraseField),
123
123
  CoreApp.serversideDeviceIdField,
124
- CoreApp.headerTokenField
124
+ this.addIdentifier(CoreApp.headerTokenField)
125
125
  ];
126
126
  }
127
127
  getDeviceId() {
@@ -129,8 +129,8 @@ class CoreApp {
129
129
  }
130
130
  resetKeys() {
131
131
  this.storage.clear([
132
- CoreApp.devicePassphraseField,
133
- CoreApp.headerTokenField,
132
+ this.addIdentifier(CoreApp.devicePassphraseField),
133
+ this.addIdentifier(CoreApp.headerTokenField),
134
134
  CoreApp.serversideDeviceIdField
135
135
  ], false);
136
136
  this.passphrase = '';
@@ -158,7 +158,8 @@ class CoreApp {
158
158
  this.resetKeys();
159
159
  return false;
160
160
  }
161
- const passphraseEncrypted = this.storage.getData(CoreApp.devicePassphraseField);
161
+ // this.name to identifier different app's secret
162
+ const passphraseEncrypted = this.storage.getData(this.addIdentifier(CoreApp.devicePassphraseField));
162
163
  if (passphraseEncrypted) {
163
164
  const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
164
165
  if (passphraseDecrypted != null) {
@@ -191,6 +192,14 @@ class CoreApp {
191
192
  return;
192
193
  this.storage.copyTo(this.persistedFields);
193
194
  }
195
+ /**
196
+ * Add app name as identifier
197
+ * @param field Field
198
+ * @returns Result
199
+ */
200
+ addIdentifier(field) {
201
+ return field + '-' + this.name;
202
+ }
194
203
  /**
195
204
  * Setup Api
196
205
  * @param api Api
@@ -313,7 +322,7 @@ class CoreApp {
313
322
  this.storage.setPersistedData(CoreApp.devicesField, devices);
314
323
  // Current passphrase
315
324
  this.passphrase = passphrase;
316
- this.storage.setData(CoreApp.devicePassphraseField, this.encrypt(passphrase, this.name));
325
+ this.storage.setData(this.addIdentifier(CoreApp.devicePassphraseField), this.encrypt(passphrase, this.name));
317
326
  // Previous passphrase
318
327
  if (data.previousPassphrase) {
319
328
  const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
@@ -345,7 +354,7 @@ class CoreApp {
345
354
  * @returns Fields
346
355
  */
347
356
  initCallEncryptedUpdateFields() {
348
- return [CoreApp.headerTokenField];
357
+ return [this.addIdentifier(CoreApp.headerTokenField)];
349
358
  }
350
359
  /**
351
360
  * Alert action result
@@ -370,7 +379,7 @@ class CoreApp {
370
379
  if (refreshToken !== '') {
371
380
  if (refreshToken != null)
372
381
  refreshToken = this.encrypt(refreshToken);
373
- this.storage.setData(CoreApp.headerTokenField, refreshToken);
382
+ this.storage.setData(this.addIdentifier(CoreApp.headerTokenField), refreshToken);
374
383
  }
375
384
  // Reset tryLogin state
376
385
  this._isTryingLogin = false;
@@ -443,14 +452,14 @@ class CoreApp {
443
452
  */
444
453
  clearCacheData() {
445
454
  this.clearCacheToken();
446
- this.storage.setData(CoreApp.devicePassphraseField, undefined);
455
+ this.storage.setData(this.addIdentifier(CoreApp.devicePassphraseField), undefined);
447
456
  }
448
457
  /**
449
458
  * Clear cached token
450
459
  */
451
460
  clearCacheToken() {
452
461
  this.cachedRefreshToken = undefined;
453
- this.storage.setPersistedData(CoreApp.headerTokenField, undefined);
462
+ this.storage.setPersistedData(this.addIdentifier(CoreApp.headerTokenField), undefined);
454
463
  }
455
464
  /**
456
465
  * Decrypt message
@@ -705,7 +714,7 @@ class CoreApp {
705
714
  // Temp refresh token
706
715
  if (this.cachedRefreshToken)
707
716
  return this.cachedRefreshToken;
708
- return this.storage.getData(CoreApp.headerTokenField);
717
+ return this.storage.getData(this.addIdentifier(CoreApp.headerTokenField));
709
718
  }
710
719
  /**
711
720
  * Get all regions
@@ -802,6 +811,13 @@ class CoreApp {
802
811
  var _a;
803
812
  (_a = this.lastWarning) === null || _a === void 0 ? void 0 : _a.dismiss();
804
813
  }
814
+ /**
815
+ * Redirect to the Url
816
+ * @param url Url
817
+ */
818
+ redirectTo(url) {
819
+ window.location.href = url;
820
+ }
805
821
  /**
806
822
  * Refresh countdown
807
823
  * @param seconds Seconds
@@ -900,7 +916,7 @@ class CoreApp {
900
916
  */
901
917
  toLoginPage(tryLogin) {
902
918
  const url = this.transformUrl('/' + (tryLogin ? '' : '?tryLogin=false'));
903
- window.location.replace(this.transformUrl('/'));
919
+ this.redirectTo(url);
904
920
  }
905
921
  /**
906
922
  * Transform URL
@@ -14,6 +14,7 @@ export interface IBridgeHost {
14
14
  /**
15
15
  * Load application
16
16
  * @param name App name
17
+ * @param startUrl Start Url
17
18
  */
18
- loadApp(name: string): void;
19
+ loadApp(name: string, startUrl?: string): void;
19
20
  }
@@ -87,7 +87,7 @@
87
87
  "settings": "系统设置",
88
88
  "showIt": "显示",
89
89
  "signout": "退出",
90
- "smartERP": "司友云ERP",
90
+ "smartERP": "司友®云ERP",
91
91
  "sortTip": "拖拽项目进行排序",
92
92
  "status": "状态",
93
93
  "statusApproved": "已批准",
@@ -87,7 +87,7 @@
87
87
  "settings": "系統設置",
88
88
  "showIt": "顯示",
89
89
  "signout": "退出",
90
- "smartERP": "司友雲ERP",
90
+ "smartERP": "司友®雲ERP",
91
91
  "sortTip": "拖拽項目進行排序",
92
92
  "status": "狀態",
93
93
  "statusApproved": "已批准",
@@ -312,6 +312,11 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
312
312
  * Persist settings to source when application exit
313
313
  */
314
314
  persist(): void;
315
+ /**
316
+ * Redirect to the Url
317
+ * @param url Url
318
+ */
319
+ redirectTo(url: string): void;
315
320
  /**
316
321
  * Switch organization
317
322
  * @param id Organization id
@@ -470,6 +475,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
470
475
  * Persist settings to source when application exit
471
476
  */
472
477
  persist(): void;
478
+ /**
479
+ * Add app name as identifier
480
+ * @param field Field
481
+ * @returns Result
482
+ */
483
+ protected addIdentifier(field: string): string;
473
484
  /**
474
485
  * Setup Api
475
486
  * @param api Api
@@ -684,6 +695,11 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
684
695
  * Callback where exit a page
685
696
  */
686
697
  pageExit(): void;
698
+ /**
699
+ * Redirect to the Url
700
+ * @param url Url
701
+ */
702
+ redirectTo(url: string): void;
687
703
  /**
688
704
  * Refresh countdown
689
705
  * @param seconds Seconds
@@ -116,9 +116,9 @@ export class CoreApp {
116
116
  get persistedFields() {
117
117
  return [
118
118
  CoreApp.deviceIdField,
119
- CoreApp.devicePassphraseField,
119
+ this.addIdentifier(CoreApp.devicePassphraseField),
120
120
  CoreApp.serversideDeviceIdField,
121
- CoreApp.headerTokenField
121
+ this.addIdentifier(CoreApp.headerTokenField)
122
122
  ];
123
123
  }
124
124
  getDeviceId() {
@@ -126,8 +126,8 @@ export class CoreApp {
126
126
  }
127
127
  resetKeys() {
128
128
  this.storage.clear([
129
- CoreApp.devicePassphraseField,
130
- CoreApp.headerTokenField,
129
+ this.addIdentifier(CoreApp.devicePassphraseField),
130
+ this.addIdentifier(CoreApp.headerTokenField),
131
131
  CoreApp.serversideDeviceIdField
132
132
  ], false);
133
133
  this.passphrase = '';
@@ -155,7 +155,8 @@ export class CoreApp {
155
155
  this.resetKeys();
156
156
  return false;
157
157
  }
158
- const passphraseEncrypted = this.storage.getData(CoreApp.devicePassphraseField);
158
+ // this.name to identifier different app's secret
159
+ const passphraseEncrypted = this.storage.getData(this.addIdentifier(CoreApp.devicePassphraseField));
159
160
  if (passphraseEncrypted) {
160
161
  const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
161
162
  if (passphraseDecrypted != null) {
@@ -188,6 +189,14 @@ export class CoreApp {
188
189
  return;
189
190
  this.storage.copyTo(this.persistedFields);
190
191
  }
192
+ /**
193
+ * Add app name as identifier
194
+ * @param field Field
195
+ * @returns Result
196
+ */
197
+ addIdentifier(field) {
198
+ return field + '-' + this.name;
199
+ }
191
200
  /**
192
201
  * Setup Api
193
202
  * @param api Api
@@ -310,7 +319,7 @@ export class CoreApp {
310
319
  this.storage.setPersistedData(CoreApp.devicesField, devices);
311
320
  // Current passphrase
312
321
  this.passphrase = passphrase;
313
- this.storage.setData(CoreApp.devicePassphraseField, this.encrypt(passphrase, this.name));
322
+ this.storage.setData(this.addIdentifier(CoreApp.devicePassphraseField), this.encrypt(passphrase, this.name));
314
323
  // Previous passphrase
315
324
  if (data.previousPassphrase) {
316
325
  const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
@@ -342,7 +351,7 @@ export class CoreApp {
342
351
  * @returns Fields
343
352
  */
344
353
  initCallEncryptedUpdateFields() {
345
- return [CoreApp.headerTokenField];
354
+ return [this.addIdentifier(CoreApp.headerTokenField)];
346
355
  }
347
356
  /**
348
357
  * Alert action result
@@ -367,7 +376,7 @@ export class CoreApp {
367
376
  if (refreshToken !== '') {
368
377
  if (refreshToken != null)
369
378
  refreshToken = this.encrypt(refreshToken);
370
- this.storage.setData(CoreApp.headerTokenField, refreshToken);
379
+ this.storage.setData(this.addIdentifier(CoreApp.headerTokenField), refreshToken);
371
380
  }
372
381
  // Reset tryLogin state
373
382
  this._isTryingLogin = false;
@@ -440,14 +449,14 @@ export class CoreApp {
440
449
  */
441
450
  clearCacheData() {
442
451
  this.clearCacheToken();
443
- this.storage.setData(CoreApp.devicePassphraseField, undefined);
452
+ this.storage.setData(this.addIdentifier(CoreApp.devicePassphraseField), undefined);
444
453
  }
445
454
  /**
446
455
  * Clear cached token
447
456
  */
448
457
  clearCacheToken() {
449
458
  this.cachedRefreshToken = undefined;
450
- this.storage.setPersistedData(CoreApp.headerTokenField, undefined);
459
+ this.storage.setPersistedData(this.addIdentifier(CoreApp.headerTokenField), undefined);
451
460
  }
452
461
  /**
453
462
  * Decrypt message
@@ -702,7 +711,7 @@ export class CoreApp {
702
711
  // Temp refresh token
703
712
  if (this.cachedRefreshToken)
704
713
  return this.cachedRefreshToken;
705
- return this.storage.getData(CoreApp.headerTokenField);
714
+ return this.storage.getData(this.addIdentifier(CoreApp.headerTokenField));
706
715
  }
707
716
  /**
708
717
  * Get all regions
@@ -799,6 +808,13 @@ export class CoreApp {
799
808
  var _a;
800
809
  (_a = this.lastWarning) === null || _a === void 0 ? void 0 : _a.dismiss();
801
810
  }
811
+ /**
812
+ * Redirect to the Url
813
+ * @param url Url
814
+ */
815
+ redirectTo(url) {
816
+ window.location.href = url;
817
+ }
802
818
  /**
803
819
  * Refresh countdown
804
820
  * @param seconds Seconds
@@ -897,7 +913,7 @@ export class CoreApp {
897
913
  */
898
914
  toLoginPage(tryLogin) {
899
915
  const url = this.transformUrl('/' + (tryLogin ? '' : '?tryLogin=false'));
900
- window.location.replace(this.transformUrl('/'));
916
+ this.redirectTo(url);
901
917
  }
902
918
  /**
903
919
  * Transform URL
@@ -14,6 +14,7 @@ export interface IBridgeHost {
14
14
  /**
15
15
  * Load application
16
16
  * @param name App name
17
+ * @param startUrl Start Url
17
18
  */
18
- loadApp(name: string): void;
19
+ loadApp(name: string, startUrl?: string): void;
19
20
  }
@@ -87,7 +87,7 @@
87
87
  "settings": "系统设置",
88
88
  "showIt": "显示",
89
89
  "signout": "退出",
90
- "smartERP": "司友云ERP",
90
+ "smartERP": "司友®云ERP",
91
91
  "sortTip": "拖拽项目进行排序",
92
92
  "status": "状态",
93
93
  "statusApproved": "已批准",
@@ -87,7 +87,7 @@
87
87
  "settings": "系統設置",
88
88
  "showIt": "顯示",
89
89
  "signout": "退出",
90
- "smartERP": "司友雲ERP",
90
+ "smartERP": "司友®雲ERP",
91
91
  "sortTip": "拖拽項目進行排序",
92
92
  "status": "狀態",
93
93
  "statusApproved": "已批准",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.2.42",
3
+ "version": "1.2.46",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -428,6 +428,12 @@ export interface ICoreApp<
428
428
  */
429
429
  persist(): void;
430
430
 
431
+ /**
432
+ * Redirect to the Url
433
+ * @param url Url
434
+ */
435
+ redirectTo(url: string): void;
436
+
431
437
  /**
432
438
  * Switch organization
433
439
  * @param id Organization id
@@ -627,9 +633,9 @@ export abstract class CoreApp<
627
633
  protected get persistedFields() {
628
634
  return [
629
635
  CoreApp.deviceIdField,
630
- CoreApp.devicePassphraseField,
636
+ this.addIdentifier(CoreApp.devicePassphraseField),
631
637
  CoreApp.serversideDeviceIdField,
632
- CoreApp.headerTokenField
638
+ this.addIdentifier(CoreApp.headerTokenField)
633
639
  ];
634
640
  }
635
641
 
@@ -678,8 +684,8 @@ export abstract class CoreApp<
678
684
  private resetKeys() {
679
685
  this.storage.clear(
680
686
  [
681
- CoreApp.devicePassphraseField,
682
- CoreApp.headerTokenField,
687
+ this.addIdentifier(CoreApp.devicePassphraseField),
688
+ this.addIdentifier(CoreApp.headerTokenField),
683
689
  CoreApp.serversideDeviceIdField
684
690
  ],
685
691
  false
@@ -717,8 +723,9 @@ export abstract class CoreApp<
717
723
  return false;
718
724
  }
719
725
 
726
+ // this.name to identifier different app's secret
720
727
  const passphraseEncrypted = this.storage.getData<string>(
721
- CoreApp.devicePassphraseField
728
+ this.addIdentifier(CoreApp.devicePassphraseField)
722
729
  );
723
730
  if (passphraseEncrypted) {
724
731
  const passphraseDecrypted = this.decrypt(
@@ -763,6 +770,15 @@ export abstract class CoreApp<
763
770
  this.storage.copyTo(this.persistedFields);
764
771
  }
765
772
 
773
+ /**
774
+ * Add app name as identifier
775
+ * @param field Field
776
+ * @returns Result
777
+ */
778
+ protected addIdentifier(field: string) {
779
+ return field + '-' + this.name;
780
+ }
781
+
766
782
  /**
767
783
  * Setup Api
768
784
  * @param api Api
@@ -907,7 +923,7 @@ export abstract class CoreApp<
907
923
  // Current passphrase
908
924
  this.passphrase = passphrase;
909
925
  this.storage.setData(
910
- CoreApp.devicePassphraseField,
926
+ this.addIdentifier(CoreApp.devicePassphraseField),
911
927
  this.encrypt(passphrase, this.name)
912
928
  );
913
929
 
@@ -953,7 +969,7 @@ export abstract class CoreApp<
953
969
  * @returns Fields
954
970
  */
955
971
  protected initCallEncryptedUpdateFields(): string[] {
956
- return [CoreApp.headerTokenField];
972
+ return [this.addIdentifier(CoreApp.headerTokenField)];
957
973
  }
958
974
 
959
975
  /**
@@ -981,7 +997,10 @@ export abstract class CoreApp<
981
997
  // Cover the current value
982
998
  if (refreshToken !== '') {
983
999
  if (refreshToken != null) refreshToken = this.encrypt(refreshToken);
984
- this.storage.setData(CoreApp.headerTokenField, refreshToken);
1000
+ this.storage.setData(
1001
+ this.addIdentifier(CoreApp.headerTokenField),
1002
+ refreshToken
1003
+ );
985
1004
  }
986
1005
 
987
1006
  // Reset tryLogin state
@@ -1069,7 +1088,10 @@ export abstract class CoreApp<
1069
1088
  */
1070
1089
  clearCacheData() {
1071
1090
  this.clearCacheToken();
1072
- this.storage.setData(CoreApp.devicePassphraseField, undefined);
1091
+ this.storage.setData(
1092
+ this.addIdentifier(CoreApp.devicePassphraseField),
1093
+ undefined
1094
+ );
1073
1095
  }
1074
1096
 
1075
1097
  /**
@@ -1077,7 +1099,10 @@ export abstract class CoreApp<
1077
1099
  */
1078
1100
  clearCacheToken() {
1079
1101
  this.cachedRefreshToken = undefined;
1080
- this.storage.setPersistedData(CoreApp.headerTokenField, undefined);
1102
+ this.storage.setPersistedData(
1103
+ this.addIdentifier(CoreApp.headerTokenField),
1104
+ undefined
1105
+ );
1081
1106
  }
1082
1107
 
1083
1108
  /**
@@ -1389,7 +1414,9 @@ export abstract class CoreApp<
1389
1414
  getCacheToken(): string | undefined {
1390
1415
  // Temp refresh token
1391
1416
  if (this.cachedRefreshToken) return this.cachedRefreshToken;
1392
- return this.storage.getData<string>(CoreApp.headerTokenField);
1417
+ return this.storage.getData<string>(
1418
+ this.addIdentifier(CoreApp.headerTokenField)
1419
+ );
1393
1420
  }
1394
1421
 
1395
1422
  /**
@@ -1496,6 +1523,14 @@ export abstract class CoreApp<
1496
1523
  this.lastWarning?.dismiss();
1497
1524
  }
1498
1525
 
1526
+ /**
1527
+ * Redirect to the Url
1528
+ * @param url Url
1529
+ */
1530
+ redirectTo(url: string): void {
1531
+ window.location.href = url;
1532
+ }
1533
+
1499
1534
  /**
1500
1535
  * Refresh countdown
1501
1536
  * @param seconds Seconds
@@ -1618,7 +1653,7 @@ export abstract class CoreApp<
1618
1653
  const url = this.transformUrl(
1619
1654
  '/' + (tryLogin ? '' : '?tryLogin=false')
1620
1655
  );
1621
- window.location.replace(this.transformUrl('/'));
1656
+ this.redirectTo(url);
1622
1657
  }
1623
1658
 
1624
1659
  /**
@@ -16,6 +16,7 @@ export interface IBridgeHost {
16
16
  /**
17
17
  * Load application
18
18
  * @param name App name
19
+ * @param startUrl Start Url
19
20
  */
20
- loadApp(name: string): void;
21
+ loadApp(name: string, startUrl?: string): void;
21
22
  }
@@ -87,7 +87,7 @@
87
87
  "settings": "系统设置",
88
88
  "showIt": "显示",
89
89
  "signout": "退出",
90
- "smartERP": "司友云ERP",
90
+ "smartERP": "司友®云ERP",
91
91
  "sortTip": "拖拽项目进行排序",
92
92
  "status": "状态",
93
93
  "statusApproved": "已批准",
@@ -87,7 +87,7 @@
87
87
  "settings": "系統設置",
88
88
  "showIt": "顯示",
89
89
  "signout": "退出",
90
- "smartERP": "司友雲ERP",
90
+ "smartERP": "司友®雲ERP",
91
91
  "sortTip": "拖拽項目進行排序",
92
92
  "status": "狀態",
93
93
  "statusApproved": "已批准",