@etsoo/appscript 1.2.68 → 1.2.71

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.
@@ -8,7 +8,7 @@ import {
8
8
  } from '@etsoo/notificationbase';
9
9
  import { ApiAuthorizationScheme, createClient } from '@etsoo/restclient';
10
10
  import { DataTypes, DomUtils, Utils, WindowStorage } from '@etsoo/shared';
11
- import { BusinessUtils } from '../../src';
11
+ import { BusinessUtils, IUser } from '../../src';
12
12
  import { AddressUtils } from '../../src/address/AddressUtils';
13
13
  import { IAppSettings } from '../../src/app/AppSettings';
14
14
  import { CoreApp } from '../../src/app/CoreApp';
@@ -49,7 +49,12 @@ class NotificationContainerTest extends NotificationContainer<
49
49
  var container = new NotificationContainerTest((update) => {});
50
50
 
51
51
  // Arrange
52
- class CoreAppTest extends CoreApp<IAppSettings, {}, NotificationCallProps> {
52
+ class CoreAppTest extends CoreApp<
53
+ IUser,
54
+ IAppSettings,
55
+ {},
56
+ NotificationCallProps
57
+ > {
53
58
  /**
54
59
  * Constructor
55
60
  * @param settings Settings
@@ -7,7 +7,7 @@ import { IdLabelDto } from '../dto/IdLabelDto';
7
7
  import { InitCallDto } from '../dto/InitCallDto';
8
8
  import { IActionResult } from '../result/IActionResult';
9
9
  import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
10
- import { IUserData } from '../state/User';
10
+ import { IUser } from '../state/User';
11
11
  import { IAppSettings } from './AppSettings';
12
12
  import { UserRole } from './UserRole';
13
13
  /**
@@ -56,7 +56,7 @@ export declare type IAppFields = {
56
56
  /**
57
57
  * Core application interface
58
58
  */
59
- export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallProps> {
59
+ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends NotificationCallProps> {
60
60
  /**
61
61
  * Settings
62
62
  */
@@ -112,7 +112,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
112
112
  /**
113
113
  * User data
114
114
  */
115
- userData?: IUserData;
115
+ userData?: U;
116
116
  /**
117
117
  * Search input element
118
118
  */
@@ -139,6 +139,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
139
139
  * @param culture New culture definition
140
140
  */
141
141
  changeCulture(culture: DataTypes.CultureDefinition): void;
142
+ /**
143
+ * Check the action result is about device invalid
144
+ * @param result Action result
145
+ * @returns true means device is invalid
146
+ */
147
+ checkDeviceResult(result: IActionResult): boolean;
142
148
  /**
143
149
  * Clear cache data
144
150
  */
@@ -373,7 +379,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
373
379
  * @param refreshToken Refresh token
374
380
  * @param keep Keep login or not
375
381
  */
376
- userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
382
+ userLogin(user: U, refreshToken: string, keep?: boolean): void;
377
383
  /**
378
384
  * User logout
379
385
  * @param clearToken Clear refresh token or not
@@ -393,7 +399,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
393
399
  /**
394
400
  * Core application
395
401
  */
396
- export declare abstract class CoreApp<S extends IAppSettings, N, C extends NotificationCallProps> implements ICoreApp<S, N, C> {
402
+ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N, C extends NotificationCallProps> implements ICoreApp<U, S, N, C> {
397
403
  /**
398
404
  * Settings
399
405
  */
@@ -452,8 +458,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
452
458
  /**
453
459
  * User data
454
460
  */
455
- get userData(): IUserData | undefined;
456
- protected set userData(value: IUserData | undefined);
461
+ get userData(): U | undefined;
462
+ protected set userData(value: U | undefined);
457
463
  private ipDetectCallbacks?;
458
464
  /**
459
465
  * Search input element
@@ -533,7 +539,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
533
539
  * @param result Action result
534
540
  * @returns true means device is invalid
535
541
  */
536
- protected checkDeviceResult(result: IActionResult): boolean;
542
+ checkDeviceResult(result: IActionResult): boolean;
537
543
  /**
538
544
  * Init call
539
545
  * @param callback Callback
@@ -816,7 +822,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
816
822
  * @param refreshToken Refresh token
817
823
  * @param keep Keep login or not
818
824
  */
819
- userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
825
+ userLogin(user: U, refreshToken: string, keep?: boolean): void;
820
826
  /**
821
827
  * User logout
822
828
  * @param clearToken Clear refresh token or not
@@ -727,10 +727,18 @@ class CoreApp {
727
727
  doRefreshTokenResult(result, initCallCallback, silent = false) {
728
728
  if (result === true)
729
729
  return;
730
- if (initCallCallback &&
731
- typeof result === 'object' &&
730
+ if (typeof result === 'object' &&
732
731
  !(result instanceof restclient_1.ApiDataError) &&
733
732
  this.checkDeviceResult(result)) {
733
+ initCallCallback !== null && initCallCallback !== void 0 ? initCallCallback : (initCallCallback = (result) => {
734
+ var _a;
735
+ if (!result)
736
+ return;
737
+ this.notifier.alert((_a = this.get('environmentChanged')) !== null && _a !== void 0 ? _a : 'Environment changed', () => {
738
+ // Reload the page
739
+ history.go(0);
740
+ });
741
+ });
734
742
  this.initCall(initCallCallback, true);
735
743
  return;
736
744
  }
@@ -7,7 +7,7 @@ import { IdLabelDto } from '../dto/IdLabelDto';
7
7
  import { InitCallDto } from '../dto/InitCallDto';
8
8
  import { IActionResult } from '../result/IActionResult';
9
9
  import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
10
- import { IUserData } from '../state/User';
10
+ import { IUser } from '../state/User';
11
11
  import { IAppSettings } from './AppSettings';
12
12
  import { UserRole } from './UserRole';
13
13
  /**
@@ -56,7 +56,7 @@ export declare type IAppFields = {
56
56
  /**
57
57
  * Core application interface
58
58
  */
59
- export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallProps> {
59
+ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends NotificationCallProps> {
60
60
  /**
61
61
  * Settings
62
62
  */
@@ -112,7 +112,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
112
112
  /**
113
113
  * User data
114
114
  */
115
- userData?: IUserData;
115
+ userData?: U;
116
116
  /**
117
117
  * Search input element
118
118
  */
@@ -139,6 +139,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
139
139
  * @param culture New culture definition
140
140
  */
141
141
  changeCulture(culture: DataTypes.CultureDefinition): void;
142
+ /**
143
+ * Check the action result is about device invalid
144
+ * @param result Action result
145
+ * @returns true means device is invalid
146
+ */
147
+ checkDeviceResult(result: IActionResult): boolean;
142
148
  /**
143
149
  * Clear cache data
144
150
  */
@@ -373,7 +379,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
373
379
  * @param refreshToken Refresh token
374
380
  * @param keep Keep login or not
375
381
  */
376
- userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
382
+ userLogin(user: U, refreshToken: string, keep?: boolean): void;
377
383
  /**
378
384
  * User logout
379
385
  * @param clearToken Clear refresh token or not
@@ -393,7 +399,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
393
399
  /**
394
400
  * Core application
395
401
  */
396
- export declare abstract class CoreApp<S extends IAppSettings, N, C extends NotificationCallProps> implements ICoreApp<S, N, C> {
402
+ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N, C extends NotificationCallProps> implements ICoreApp<U, S, N, C> {
397
403
  /**
398
404
  * Settings
399
405
  */
@@ -452,8 +458,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
452
458
  /**
453
459
  * User data
454
460
  */
455
- get userData(): IUserData | undefined;
456
- protected set userData(value: IUserData | undefined);
461
+ get userData(): U | undefined;
462
+ protected set userData(value: U | undefined);
457
463
  private ipDetectCallbacks?;
458
464
  /**
459
465
  * Search input element
@@ -533,7 +539,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
533
539
  * @param result Action result
534
540
  * @returns true means device is invalid
535
541
  */
536
- protected checkDeviceResult(result: IActionResult): boolean;
542
+ checkDeviceResult(result: IActionResult): boolean;
537
543
  /**
538
544
  * Init call
539
545
  * @param callback Callback
@@ -816,7 +822,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
816
822
  * @param refreshToken Refresh token
817
823
  * @param keep Keep login or not
818
824
  */
819
- userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
825
+ userLogin(user: U, refreshToken: string, keep?: boolean): void;
820
826
  /**
821
827
  * User logout
822
828
  * @param clearToken Clear refresh token or not
@@ -724,10 +724,18 @@ export class CoreApp {
724
724
  doRefreshTokenResult(result, initCallCallback, silent = false) {
725
725
  if (result === true)
726
726
  return;
727
- if (initCallCallback &&
728
- typeof result === 'object' &&
727
+ if (typeof result === 'object' &&
729
728
  !(result instanceof ApiDataError) &&
730
729
  this.checkDeviceResult(result)) {
730
+ initCallCallback !== null && initCallCallback !== void 0 ? initCallCallback : (initCallCallback = (result) => {
731
+ var _a;
732
+ if (!result)
733
+ return;
734
+ this.notifier.alert((_a = this.get('environmentChanged')) !== null && _a !== void 0 ? _a : 'Environment changed', () => {
735
+ // Reload the page
736
+ history.go(0);
737
+ });
738
+ });
731
739
  this.initCall(initCallCallback, true);
732
740
  return;
733
741
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.2.68",
3
+ "version": "1.2.71",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -37,7 +37,7 @@ import { InitCallDto } from '../dto/InitCallDto';
37
37
  import { ActionResultError } from '../result/ActionResultError';
38
38
  import { IActionResult } from '../result/IActionResult';
39
39
  import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
40
- import { IUserData } from '../state/User';
40
+ import { IUser, IUserData } from '../state/User';
41
41
  import { IAppSettings } from './AppSettings';
42
42
  import { UserRole } from './UserRole';
43
43
 
@@ -104,6 +104,7 @@ export type IAppFields = { [key in typeof appFields[number]]: string };
104
104
  * Core application interface
105
105
  */
106
106
  export interface ICoreApp<
107
+ U extends IUser,
107
108
  S extends IAppSettings,
108
109
  N,
109
110
  C extends NotificationCallProps
@@ -176,7 +177,7 @@ export interface ICoreApp<
176
177
  /**
177
178
  * User data
178
179
  */
179
- userData?: IUserData;
180
+ userData?: U;
180
181
 
181
182
  /**
182
183
  * Search input element
@@ -212,6 +213,13 @@ export interface ICoreApp<
212
213
  */
213
214
  changeCulture(culture: DataTypes.CultureDefinition): void;
214
215
 
216
+ /**
217
+ * Check the action result is about device invalid
218
+ * @param result Action result
219
+ * @returns true means device is invalid
220
+ */
221
+ checkDeviceResult(result: IActionResult): boolean;
222
+
215
223
  /**
216
224
  * Clear cache data
217
225
  */
@@ -511,7 +519,7 @@ export interface ICoreApp<
511
519
  * @param refreshToken Refresh token
512
520
  * @param keep Keep login or not
513
521
  */
514
- userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
522
+ userLogin(user: U, refreshToken: string, keep?: boolean): void;
515
523
 
516
524
  /**
517
525
  * User logout
@@ -536,10 +544,11 @@ export interface ICoreApp<
536
544
  * Core application
537
545
  */
538
546
  export abstract class CoreApp<
547
+ U extends IUser,
539
548
  S extends IAppSettings,
540
549
  N,
541
550
  C extends NotificationCallProps
542
- > implements ICoreApp<S, N, C>
551
+ > implements ICoreApp<U, S, N, C>
543
552
  {
544
553
  /**
545
554
  * Settings
@@ -621,14 +630,14 @@ export abstract class CoreApp<
621
630
  this._ipData = value;
622
631
  }
623
632
 
624
- private _userData?: IUserData;
633
+ private _userData?: U;
625
634
  /**
626
635
  * User data
627
636
  */
628
637
  get userData() {
629
638
  return this._userData;
630
639
  }
631
- protected set userData(value: IUserData | undefined) {
640
+ protected set userData(value: U | undefined) {
632
641
  this._userData = value;
633
642
  }
634
643
 
@@ -901,7 +910,7 @@ export abstract class CoreApp<
901
910
  * @param result Action result
902
911
  * @returns true means device is invalid
903
912
  */
904
- protected checkDeviceResult(result: IActionResult): boolean {
913
+ checkDeviceResult(result: IActionResult): boolean {
905
914
  if (result.type === 'NoValidData' && result.field === 'Device')
906
915
  return true;
907
916
  return false;
@@ -1470,11 +1479,22 @@ export abstract class CoreApp<
1470
1479
  if (result === true) return;
1471
1480
 
1472
1481
  if (
1473
- initCallCallback &&
1474
1482
  typeof result === 'object' &&
1475
1483
  !(result instanceof ApiDataError) &&
1476
1484
  this.checkDeviceResult(result)
1477
1485
  ) {
1486
+ initCallCallback ??= (result) => {
1487
+ if (!result) return;
1488
+ this.notifier.alert(
1489
+ this.get<string>('environmentChanged') ??
1490
+ 'Environment changed',
1491
+ () => {
1492
+ // Reload the page
1493
+ history.go(0);
1494
+ }
1495
+ );
1496
+ };
1497
+
1478
1498
  this.initCall(initCallCallback, true);
1479
1499
  return;
1480
1500
  }
@@ -1852,7 +1872,7 @@ export abstract class CoreApp<
1852
1872
  * @param refreshToken Refresh token
1853
1873
  * @param keep Keep login or not
1854
1874
  */
1855
- userLogin(user: IUserData, refreshToken: string, keep?: boolean) {
1875
+ userLogin(user: U, refreshToken: string, keep?: boolean) {
1856
1876
  this.userData = user;
1857
1877
 
1858
1878
  // Cache the encrypted serverside device id