@etsoo/appscript 1.5.41 → 1.5.43

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.
@@ -7,7 +7,7 @@ import { InitCallDto } from '../erp/dto/InitCallDto';
7
7
  import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
8
8
  import { IUser } from '../state/User';
9
9
  import { IAppSettings } from './AppSettings';
10
- import { FormatResultCustomCallback, IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps, RefreshTokenResult } from './IApp';
10
+ import { AppLoginParams, FormatResultCustomCallback, IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps, RefreshTokenResult } from './IApp';
11
11
  import { UserRole } from './UserRole';
12
12
  import { ExternalEndpoint } from './ExternalSettings';
13
13
  import { ApiRefreshTokenDto } from '../erp/dto/ApiRefreshTokenDto';
@@ -135,6 +135,11 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
135
135
  */
136
136
  get embedded(): boolean;
137
137
  private _isTryingLogin;
138
+ /**
139
+ * Is trying login
140
+ */
141
+ get isTryingLogin(): boolean;
142
+ protected set isTryingLogin(value: boolean);
138
143
  /**
139
144
  * Last called with token refresh
140
145
  */
@@ -415,17 +420,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
415
420
  * @returns Error message
416
421
  */
417
422
  formatError(error: ApiDataError): string;
418
- /**
419
- * Refresh token failed
420
- */
421
- protected refreshTokenFailed(): void;
422
- /**
423
- * Do refresh token result
424
- * @param result Result
425
- * @param initCallCallback InitCall callback
426
- * @param silent Silent without any popups
427
- */
428
- doRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
429
423
  /**
430
424
  * Format as full name
431
425
  * @param familyName Family name
@@ -437,7 +431,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
437
431
  * @param result Refresh token result
438
432
  * @returns Message
439
433
  */
440
- formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>): string | undefined;
434
+ protected formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>): string | undefined;
441
435
  private getFieldLabel;
442
436
  /**
443
437
  * Format result text
@@ -588,7 +582,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
588
582
  * Refresh token
589
583
  * @param props Props
590
584
  */
591
- refreshToken(props?: RefreshTokenProps): Promise<boolean>;
585
+ refreshToken(props?: RefreshTokenProps): Promise<void>;
592
586
  /**
593
587
  * Setup callback
594
588
  */
@@ -630,16 +624,15 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
630
624
  signout(): Promise<void>;
631
625
  /**
632
626
  * Go to the login page
633
- * @param tryLogin Try to login again
634
- * @param removeUrl Remove current URL for reuse
627
+ * params Login parameters
635
628
  */
636
- toLoginPage(tryLogin?: boolean, removeUrl?: boolean): void;
629
+ toLoginPage(params?: AppLoginParams): void;
637
630
  /**
638
631
  * Try login, returning false means is loading
639
632
  * UI get involved while refreshToken not intended
640
- * @param showLoading Show loading bar or not during call
633
+ * @param params Login parameters
641
634
  */
642
- tryLogin(_showLoading?: boolean): Promise<boolean>;
635
+ tryLogin(params?: AppLoginParams): Promise<void>;
643
636
  /**
644
637
  * Update embedded status
645
638
  * @param embedded New embedded status
@@ -102,6 +102,15 @@ class CoreApp {
102
102
  get embedded() {
103
103
  return this._embedded;
104
104
  }
105
+ /**
106
+ * Is trying login
107
+ */
108
+ get isTryingLogin() {
109
+ return this._isTryingLogin;
110
+ }
111
+ set isTryingLogin(value) {
112
+ this._isTryingLogin = value;
113
+ }
105
114
  /**
106
115
  * Get persisted fields
107
116
  */
@@ -995,44 +1004,6 @@ class CoreApp {
995
1004
  formatError(error) {
996
1005
  return `${error.message} (${error.name})`;
997
1006
  }
998
- /**
999
- * Refresh token failed
1000
- */
1001
- refreshTokenFailed() {
1002
- this.userUnauthorized();
1003
- this.toLoginPage();
1004
- }
1005
- /**
1006
- * Do refresh token result
1007
- * @param result Result
1008
- * @param initCallCallback InitCall callback
1009
- * @param silent Silent without any popups
1010
- */
1011
- doRefreshTokenResult(result, initCallCallback, silent = false) {
1012
- if (Array.isArray(result) &&
1013
- !(result instanceof restclient_1.ApiDataError) &&
1014
- this.checkDeviceResult(result[1])) {
1015
- initCallCallback ?? (initCallCallback = (result) => {
1016
- if (!result)
1017
- return;
1018
- this.notifier.alert(this.get('environmentChanged') ??
1019
- 'Environment changed', () => {
1020
- // Reload the page
1021
- history.go(0);
1022
- });
1023
- });
1024
- this.initCall(initCallCallback, true);
1025
- return;
1026
- }
1027
- const message = this.formatRefreshTokenResult(result);
1028
- if (message == null || silent) {
1029
- this.refreshTokenFailed();
1030
- return;
1031
- }
1032
- this.notifier.alert(message, () => {
1033
- this.refreshTokenFailed();
1034
- });
1035
- }
1036
1007
  /**
1037
1008
  * Format as full name
1038
1009
  * @param familyName Family name
@@ -1406,9 +1377,7 @@ class CoreApp {
1406
1377
  * Refresh token
1407
1378
  * @param props Props
1408
1379
  */
1409
- async refreshToken(props) {
1410
- return true;
1411
- }
1380
+ async refreshToken(props) { }
1412
1381
  /**
1413
1382
  * Setup callback
1414
1383
  */
@@ -1579,29 +1548,32 @@ class CoreApp {
1579
1548
  // Clear, noTrigger = true, avoid state update
1580
1549
  this.userLogout(true, true);
1581
1550
  // Go to login page
1582
- this.toLoginPage(false, true);
1551
+ this.toLoginPage({ tryLogin: false, removeUrl: true });
1583
1552
  }
1584
1553
  /**
1585
1554
  * Go to the login page
1586
- * @param tryLogin Try to login again
1587
- * @param removeUrl Remove current URL for reuse
1555
+ * params Login parameters
1588
1556
  */
1589
- toLoginPage(tryLogin, removeUrl) {
1557
+ toLoginPage(params) {
1558
+ // Destruct
1559
+ const { removeUrl, showLoading, ...rest } = params ?? {};
1590
1560
  // Save the current URL
1591
1561
  this.cachedUrl = removeUrl ? undefined : globalThis.location.href;
1592
- const url = `/?tryLogin=${tryLogin ?? false}`;
1562
+ // URL with parameters
1563
+ const url = '/'.addUrlParams(rest);
1593
1564
  this.navigate(url);
1594
1565
  }
1595
1566
  /**
1596
1567
  * Try login, returning false means is loading
1597
1568
  * UI get involved while refreshToken not intended
1598
- * @param showLoading Show loading bar or not during call
1569
+ * @param params Login parameters
1599
1570
  */
1600
- async tryLogin(_showLoading) {
1571
+ async tryLogin(params) {
1572
+ // Check status
1601
1573
  if (this._isTryingLogin)
1602
- return false;
1574
+ return;
1603
1575
  this._isTryingLogin = true;
1604
- return true;
1576
+ this.toLoginPage(params);
1605
1577
  }
1606
1578
  /**
1607
1579
  * Update embedded status
@@ -40,6 +40,23 @@ export type FormatResultCustom = {
40
40
  * Format result custom callback type
41
41
  */
42
42
  export type FormatResultCustomCallback = ((data: FormatResultCustom) => string | null | undefined) | boolean;
43
+ /**
44
+ * Login parameters
45
+ */
46
+ export type AppLoginParams = DataTypes.SimpleObject & {
47
+ /**
48
+ * Try login with cached refresh token
49
+ */
50
+ tryLogin?: boolean;
51
+ /**
52
+ * Don't cache current URL instead of the default page
53
+ */
54
+ removeUrl?: boolean;
55
+ /**
56
+ * Show loading bar or not
57
+ */
58
+ showLoading?: boolean;
59
+ };
43
60
  /**
44
61
  * Refresh token props
45
62
  */
@@ -48,6 +65,11 @@ export interface RefreshTokenProps {
48
65
  * API name
49
66
  */
50
67
  api?: string;
68
+ /**
69
+ * Callback
70
+ * @param result Result
71
+ */
72
+ callback?: (result: boolean) => void;
51
73
  /**
52
74
  * Show loading bar or not
53
75
  */
@@ -123,6 +145,10 @@ export interface IApp {
123
145
  * Is the app ready
124
146
  */
125
147
  readonly isReady: boolean;
148
+ /**
149
+ * Is trying to login
150
+ */
151
+ readonly isTryingLogin: boolean;
126
152
  /**
127
153
  * Application name
128
154
  */
@@ -329,25 +355,12 @@ export interface IApp {
329
355
  * @returns Result
330
356
  */
331
357
  formatNumber(input: number | bigint, options?: Intl.NumberFormatOptions): string;
332
- /**
333
- * Do refresh token result
334
- * @param result Result
335
- * @param initCallCallback InitCall callback
336
- * @param silent Silent without any popups
337
- */
338
- doRefreshTokenResult(result: RefreshTokenResult<IActionResult<IUser>>, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
339
358
  /**
340
359
  * Format as full name
341
360
  * @param familyName Family name
342
361
  * @param givenName Given name
343
362
  */
344
363
  formatFullName(familyName: string | undefined | null, givenName: string | undefined | null): string;
345
- /**
346
- * Format refresh token result
347
- * @param result Refresh token result
348
- * @returns Message
349
- */
350
- formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<IUser>>): string | undefined;
351
364
  /**
352
365
  * Format result text
353
366
  * @param result Action result
@@ -510,7 +523,7 @@ export interface IApp {
510
523
  * Refresh token
511
524
  * @param props Props
512
525
  */
513
- refreshToken(props?: RefreshTokenProps): Promise<boolean>;
526
+ refreshToken(props?: RefreshTokenProps): Promise<void>;
514
527
  /**
515
528
  * Setup Api error handler
516
529
  * @param api Api
@@ -538,16 +551,15 @@ export interface IApp {
538
551
  persist(): void;
539
552
  /**
540
553
  * Go to the login page
541
- * @param tryLogin Try to login again
542
- * @param removeUrl Remove current URL for reuse
554
+ * @param params Login parameters
543
555
  */
544
- toLoginPage(tryLogin?: boolean, removeUrl?: boolean): void;
556
+ toLoginPage(params?: AppLoginParams): void;
545
557
  /**
546
558
  * Try login, returning false means is loading
547
559
  * UI get involved while refreshToken not intended
548
- * @param showLoading Show loading bar or not
560
+ * @param params Login parameters
549
561
  */
550
- tryLogin(showLoading?: boolean): Promise<boolean>;
562
+ tryLogin(params?: AppLoginParams): Promise<void>;
551
563
  /**
552
564
  * Update API token and expires
553
565
  * @param name Api name
@@ -63,7 +63,7 @@ export declare class OrgApi extends EntityApi {
63
63
  * @param serviceId Service id
64
64
  * @param payload Payload
65
65
  */
66
- switch(id: number, serviceId?: number, payload?: IApiPayload<boolean>): Promise<boolean | undefined>;
66
+ switch(id: number, serviceId?: number, payload?: IApiPayload<boolean>): Promise<false | void>;
67
67
  /**
68
68
  * Update
69
69
  * @param data Modal data
@@ -7,7 +7,7 @@ import { InitCallDto } from '../erp/dto/InitCallDto';
7
7
  import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
8
8
  import { IUser } from '../state/User';
9
9
  import { IAppSettings } from './AppSettings';
10
- import { FormatResultCustomCallback, IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps, RefreshTokenResult } from './IApp';
10
+ import { AppLoginParams, FormatResultCustomCallback, IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps, RefreshTokenResult } from './IApp';
11
11
  import { UserRole } from './UserRole';
12
12
  import { ExternalEndpoint } from './ExternalSettings';
13
13
  import { ApiRefreshTokenDto } from '../erp/dto/ApiRefreshTokenDto';
@@ -135,6 +135,11 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
135
135
  */
136
136
  get embedded(): boolean;
137
137
  private _isTryingLogin;
138
+ /**
139
+ * Is trying login
140
+ */
141
+ get isTryingLogin(): boolean;
142
+ protected set isTryingLogin(value: boolean);
138
143
  /**
139
144
  * Last called with token refresh
140
145
  */
@@ -415,17 +420,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
415
420
  * @returns Error message
416
421
  */
417
422
  formatError(error: ApiDataError): string;
418
- /**
419
- * Refresh token failed
420
- */
421
- protected refreshTokenFailed(): void;
422
- /**
423
- * Do refresh token result
424
- * @param result Result
425
- * @param initCallCallback InitCall callback
426
- * @param silent Silent without any popups
427
- */
428
- doRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
429
423
  /**
430
424
  * Format as full name
431
425
  * @param familyName Family name
@@ -437,7 +431,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
437
431
  * @param result Refresh token result
438
432
  * @returns Message
439
433
  */
440
- formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>): string | undefined;
434
+ protected formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>): string | undefined;
441
435
  private getFieldLabel;
442
436
  /**
443
437
  * Format result text
@@ -588,7 +582,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
588
582
  * Refresh token
589
583
  * @param props Props
590
584
  */
591
- refreshToken(props?: RefreshTokenProps): Promise<boolean>;
585
+ refreshToken(props?: RefreshTokenProps): Promise<void>;
592
586
  /**
593
587
  * Setup callback
594
588
  */
@@ -630,16 +624,15 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
630
624
  signout(): Promise<void>;
631
625
  /**
632
626
  * Go to the login page
633
- * @param tryLogin Try to login again
634
- * @param removeUrl Remove current URL for reuse
627
+ * params Login parameters
635
628
  */
636
- toLoginPage(tryLogin?: boolean, removeUrl?: boolean): void;
629
+ toLoginPage(params?: AppLoginParams): void;
637
630
  /**
638
631
  * Try login, returning false means is loading
639
632
  * UI get involved while refreshToken not intended
640
- * @param showLoading Show loading bar or not during call
633
+ * @param params Login parameters
641
634
  */
642
- tryLogin(_showLoading?: boolean): Promise<boolean>;
635
+ tryLogin(params?: AppLoginParams): Promise<void>;
643
636
  /**
644
637
  * Update embedded status
645
638
  * @param embedded New embedded status
@@ -99,6 +99,15 @@ export class CoreApp {
99
99
  get embedded() {
100
100
  return this._embedded;
101
101
  }
102
+ /**
103
+ * Is trying login
104
+ */
105
+ get isTryingLogin() {
106
+ return this._isTryingLogin;
107
+ }
108
+ set isTryingLogin(value) {
109
+ this._isTryingLogin = value;
110
+ }
102
111
  /**
103
112
  * Get persisted fields
104
113
  */
@@ -992,44 +1001,6 @@ export class CoreApp {
992
1001
  formatError(error) {
993
1002
  return `${error.message} (${error.name})`;
994
1003
  }
995
- /**
996
- * Refresh token failed
997
- */
998
- refreshTokenFailed() {
999
- this.userUnauthorized();
1000
- this.toLoginPage();
1001
- }
1002
- /**
1003
- * Do refresh token result
1004
- * @param result Result
1005
- * @param initCallCallback InitCall callback
1006
- * @param silent Silent without any popups
1007
- */
1008
- doRefreshTokenResult(result, initCallCallback, silent = false) {
1009
- if (Array.isArray(result) &&
1010
- !(result instanceof ApiDataError) &&
1011
- this.checkDeviceResult(result[1])) {
1012
- initCallCallback ?? (initCallCallback = (result) => {
1013
- if (!result)
1014
- return;
1015
- this.notifier.alert(this.get('environmentChanged') ??
1016
- 'Environment changed', () => {
1017
- // Reload the page
1018
- history.go(0);
1019
- });
1020
- });
1021
- this.initCall(initCallCallback, true);
1022
- return;
1023
- }
1024
- const message = this.formatRefreshTokenResult(result);
1025
- if (message == null || silent) {
1026
- this.refreshTokenFailed();
1027
- return;
1028
- }
1029
- this.notifier.alert(message, () => {
1030
- this.refreshTokenFailed();
1031
- });
1032
- }
1033
1004
  /**
1034
1005
  * Format as full name
1035
1006
  * @param familyName Family name
@@ -1403,9 +1374,7 @@ export class CoreApp {
1403
1374
  * Refresh token
1404
1375
  * @param props Props
1405
1376
  */
1406
- async refreshToken(props) {
1407
- return true;
1408
- }
1377
+ async refreshToken(props) { }
1409
1378
  /**
1410
1379
  * Setup callback
1411
1380
  */
@@ -1576,29 +1545,32 @@ export class CoreApp {
1576
1545
  // Clear, noTrigger = true, avoid state update
1577
1546
  this.userLogout(true, true);
1578
1547
  // Go to login page
1579
- this.toLoginPage(false, true);
1548
+ this.toLoginPage({ tryLogin: false, removeUrl: true });
1580
1549
  }
1581
1550
  /**
1582
1551
  * Go to the login page
1583
- * @param tryLogin Try to login again
1584
- * @param removeUrl Remove current URL for reuse
1552
+ * params Login parameters
1585
1553
  */
1586
- toLoginPage(tryLogin, removeUrl) {
1554
+ toLoginPage(params) {
1555
+ // Destruct
1556
+ const { removeUrl, showLoading, ...rest } = params ?? {};
1587
1557
  // Save the current URL
1588
1558
  this.cachedUrl = removeUrl ? undefined : globalThis.location.href;
1589
- const url = `/?tryLogin=${tryLogin ?? false}`;
1559
+ // URL with parameters
1560
+ const url = '/'.addUrlParams(rest);
1590
1561
  this.navigate(url);
1591
1562
  }
1592
1563
  /**
1593
1564
  * Try login, returning false means is loading
1594
1565
  * UI get involved while refreshToken not intended
1595
- * @param showLoading Show loading bar or not during call
1566
+ * @param params Login parameters
1596
1567
  */
1597
- async tryLogin(_showLoading) {
1568
+ async tryLogin(params) {
1569
+ // Check status
1598
1570
  if (this._isTryingLogin)
1599
- return false;
1571
+ return;
1600
1572
  this._isTryingLogin = true;
1601
- return true;
1573
+ this.toLoginPage(params);
1602
1574
  }
1603
1575
  /**
1604
1576
  * Update embedded status
@@ -40,6 +40,23 @@ export type FormatResultCustom = {
40
40
  * Format result custom callback type
41
41
  */
42
42
  export type FormatResultCustomCallback = ((data: FormatResultCustom) => string | null | undefined) | boolean;
43
+ /**
44
+ * Login parameters
45
+ */
46
+ export type AppLoginParams = DataTypes.SimpleObject & {
47
+ /**
48
+ * Try login with cached refresh token
49
+ */
50
+ tryLogin?: boolean;
51
+ /**
52
+ * Don't cache current URL instead of the default page
53
+ */
54
+ removeUrl?: boolean;
55
+ /**
56
+ * Show loading bar or not
57
+ */
58
+ showLoading?: boolean;
59
+ };
43
60
  /**
44
61
  * Refresh token props
45
62
  */
@@ -48,6 +65,11 @@ export interface RefreshTokenProps {
48
65
  * API name
49
66
  */
50
67
  api?: string;
68
+ /**
69
+ * Callback
70
+ * @param result Result
71
+ */
72
+ callback?: (result: boolean) => void;
51
73
  /**
52
74
  * Show loading bar or not
53
75
  */
@@ -123,6 +145,10 @@ export interface IApp {
123
145
  * Is the app ready
124
146
  */
125
147
  readonly isReady: boolean;
148
+ /**
149
+ * Is trying to login
150
+ */
151
+ readonly isTryingLogin: boolean;
126
152
  /**
127
153
  * Application name
128
154
  */
@@ -329,25 +355,12 @@ export interface IApp {
329
355
  * @returns Result
330
356
  */
331
357
  formatNumber(input: number | bigint, options?: Intl.NumberFormatOptions): string;
332
- /**
333
- * Do refresh token result
334
- * @param result Result
335
- * @param initCallCallback InitCall callback
336
- * @param silent Silent without any popups
337
- */
338
- doRefreshTokenResult(result: RefreshTokenResult<IActionResult<IUser>>, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
339
358
  /**
340
359
  * Format as full name
341
360
  * @param familyName Family name
342
361
  * @param givenName Given name
343
362
  */
344
363
  formatFullName(familyName: string | undefined | null, givenName: string | undefined | null): string;
345
- /**
346
- * Format refresh token result
347
- * @param result Refresh token result
348
- * @returns Message
349
- */
350
- formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<IUser>>): string | undefined;
351
364
  /**
352
365
  * Format result text
353
366
  * @param result Action result
@@ -510,7 +523,7 @@ export interface IApp {
510
523
  * Refresh token
511
524
  * @param props Props
512
525
  */
513
- refreshToken(props?: RefreshTokenProps): Promise<boolean>;
526
+ refreshToken(props?: RefreshTokenProps): Promise<void>;
514
527
  /**
515
528
  * Setup Api error handler
516
529
  * @param api Api
@@ -538,16 +551,15 @@ export interface IApp {
538
551
  persist(): void;
539
552
  /**
540
553
  * Go to the login page
541
- * @param tryLogin Try to login again
542
- * @param removeUrl Remove current URL for reuse
554
+ * @param params Login parameters
543
555
  */
544
- toLoginPage(tryLogin?: boolean, removeUrl?: boolean): void;
556
+ toLoginPage(params?: AppLoginParams): void;
545
557
  /**
546
558
  * Try login, returning false means is loading
547
559
  * UI get involved while refreshToken not intended
548
- * @param showLoading Show loading bar or not
560
+ * @param params Login parameters
549
561
  */
550
- tryLogin(showLoading?: boolean): Promise<boolean>;
562
+ tryLogin(params?: AppLoginParams): Promise<void>;
551
563
  /**
552
564
  * Update API token and expires
553
565
  * @param name Api name
@@ -63,7 +63,7 @@ export declare class OrgApi extends EntityApi {
63
63
  * @param serviceId Service id
64
64
  * @param payload Payload
65
65
  */
66
- switch(id: number, serviceId?: number, payload?: IApiPayload<boolean>): Promise<boolean | undefined>;
66
+ switch(id: number, serviceId?: number, payload?: IApiPayload<boolean>): Promise<false | void>;
67
67
  /**
68
68
  * Update
69
69
  * @param data Modal data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.5.41",
3
+ "version": "1.5.43",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -33,6 +33,7 @@ import { IUser } from '../state/User';
33
33
  import { IAppSettings } from './AppSettings';
34
34
  import {
35
35
  appFields,
36
+ AppLoginParams,
36
37
  FormatResultCustomCallback,
37
38
  IApp,
38
39
  IAppFields,
@@ -257,6 +258,15 @@ export abstract class CoreApp<
257
258
  }
258
259
 
259
260
  private _isTryingLogin = false;
261
+ /**
262
+ * Is trying login
263
+ */
264
+ get isTryingLogin() {
265
+ return this._isTryingLogin;
266
+ }
267
+ protected set isTryingLogin(value: boolean) {
268
+ this._isTryingLogin = value;
269
+ }
260
270
 
261
271
  /**
262
272
  * Last called with token refresh
@@ -1466,57 +1476,6 @@ export abstract class CoreApp<
1466
1476
  return `${error.message} (${error.name})`;
1467
1477
  }
1468
1478
 
1469
- /**
1470
- * Refresh token failed
1471
- */
1472
- protected refreshTokenFailed() {
1473
- this.userUnauthorized();
1474
- this.toLoginPage();
1475
- }
1476
-
1477
- /**
1478
- * Do refresh token result
1479
- * @param result Result
1480
- * @param initCallCallback InitCall callback
1481
- * @param silent Silent without any popups
1482
- */
1483
- doRefreshTokenResult(
1484
- result: RefreshTokenResult<IActionResult<U>>,
1485
- initCallCallback?: (result: boolean) => void,
1486
- silent: boolean = false
1487
- ) {
1488
- if (
1489
- Array.isArray(result) &&
1490
- !(result instanceof ApiDataError) &&
1491
- this.checkDeviceResult(result[1])
1492
- ) {
1493
- initCallCallback ??= (result) => {
1494
- if (!result) return;
1495
- this.notifier.alert(
1496
- this.get<string>('environmentChanged') ??
1497
- 'Environment changed',
1498
- () => {
1499
- // Reload the page
1500
- history.go(0);
1501
- }
1502
- );
1503
- };
1504
-
1505
- this.initCall(initCallCallback, true);
1506
- return;
1507
- }
1508
-
1509
- const message = this.formatRefreshTokenResult(result);
1510
- if (message == null || silent) {
1511
- this.refreshTokenFailed();
1512
- return;
1513
- }
1514
-
1515
- this.notifier.alert(message, () => {
1516
- this.refreshTokenFailed();
1517
- });
1518
- }
1519
-
1520
1479
  /**
1521
1480
  * Format as full name
1522
1481
  * @param familyName Family name
@@ -1540,7 +1499,9 @@ export abstract class CoreApp<
1540
1499
  * @param result Refresh token result
1541
1500
  * @returns Message
1542
1501
  */
1543
- formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>) {
1502
+ protected formatRefreshTokenResult(
1503
+ result: RefreshTokenResult<IActionResult<U>>
1504
+ ): string | undefined {
1544
1505
  // Error message
1545
1506
  if (typeof result === 'string') return result;
1546
1507
 
@@ -1948,9 +1909,7 @@ export abstract class CoreApp<
1948
1909
  * Refresh token
1949
1910
  * @param props Props
1950
1911
  */
1951
- async refreshToken(props?: RefreshTokenProps) {
1952
- return true;
1953
- }
1912
+ async refreshToken(props?: RefreshTokenProps) {}
1954
1913
 
1955
1914
  /**
1956
1915
  * Setup callback
@@ -2166,19 +2125,22 @@ export abstract class CoreApp<
2166
2125
  this.userLogout(true, true);
2167
2126
 
2168
2127
  // Go to login page
2169
- this.toLoginPage(false, true);
2128
+ this.toLoginPage({ tryLogin: false, removeUrl: true });
2170
2129
  }
2171
2130
 
2172
2131
  /**
2173
2132
  * Go to the login page
2174
- * @param tryLogin Try to login again
2175
- * @param removeUrl Remove current URL for reuse
2133
+ * params Login parameters
2176
2134
  */
2177
- toLoginPage(tryLogin?: boolean, removeUrl?: boolean) {
2135
+ toLoginPage(params?: AppLoginParams) {
2136
+ // Destruct
2137
+ const { removeUrl, showLoading, ...rest } = params ?? {};
2138
+
2178
2139
  // Save the current URL
2179
2140
  this.cachedUrl = removeUrl ? undefined : globalThis.location.href;
2180
2141
 
2181
- const url = `/?tryLogin=${tryLogin ?? false}`;
2142
+ // URL with parameters
2143
+ const url = '/'.addUrlParams(rest);
2182
2144
 
2183
2145
  this.navigate(url);
2184
2146
  }
@@ -2186,12 +2148,14 @@ export abstract class CoreApp<
2186
2148
  /**
2187
2149
  * Try login, returning false means is loading
2188
2150
  * UI get involved while refreshToken not intended
2189
- * @param showLoading Show loading bar or not during call
2151
+ * @param params Login parameters
2190
2152
  */
2191
- async tryLogin(_showLoading?: boolean) {
2192
- if (this._isTryingLogin) return false;
2153
+ async tryLogin(params?: AppLoginParams) {
2154
+ // Check status
2155
+ if (this._isTryingLogin) return;
2193
2156
  this._isTryingLogin = true;
2194
- return true;
2157
+
2158
+ this.toLoginPage(params);
2195
2159
  }
2196
2160
 
2197
2161
  /**
package/src/app/IApp.ts CHANGED
@@ -63,6 +63,26 @@ export type FormatResultCustomCallback =
63
63
  | ((data: FormatResultCustom) => string | null | undefined)
64
64
  | boolean;
65
65
 
66
+ /**
67
+ * Login parameters
68
+ */
69
+ export type AppLoginParams = DataTypes.SimpleObject & {
70
+ /**
71
+ * Try login with cached refresh token
72
+ */
73
+ tryLogin?: boolean;
74
+
75
+ /**
76
+ * Don't cache current URL instead of the default page
77
+ */
78
+ removeUrl?: boolean;
79
+
80
+ /**
81
+ * Show loading bar or not
82
+ */
83
+ showLoading?: boolean;
84
+ };
85
+
66
86
  /**
67
87
  * Refresh token props
68
88
  */
@@ -72,6 +92,12 @@ export interface RefreshTokenProps {
72
92
  */
73
93
  api?: string;
74
94
 
95
+ /**
96
+ * Callback
97
+ * @param result Result
98
+ */
99
+ callback?: (result: boolean) => void;
100
+
75
101
  /**
76
102
  * Show loading bar or not
77
103
  */
@@ -170,6 +196,11 @@ export interface IApp {
170
196
  */
171
197
  readonly isReady: boolean;
172
198
 
199
+ /**
200
+ * Is trying to login
201
+ */
202
+ readonly isTryingLogin: boolean;
203
+
173
204
  /**
174
205
  * Application name
175
206
  */
@@ -448,18 +479,6 @@ export interface IApp {
448
479
  options?: Intl.NumberFormatOptions
449
480
  ): string;
450
481
 
451
- /**
452
- * Do refresh token result
453
- * @param result Result
454
- * @param initCallCallback InitCall callback
455
- * @param silent Silent without any popups
456
- */
457
- doRefreshTokenResult(
458
- result: RefreshTokenResult<IActionResult<IUser>>,
459
- initCallCallback?: (result: boolean) => void,
460
- silent?: boolean
461
- ): void;
462
-
463
482
  /**
464
483
  * Format as full name
465
484
  * @param familyName Family name
@@ -470,15 +489,6 @@ export interface IApp {
470
489
  givenName: string | undefined | null
471
490
  ): string;
472
491
 
473
- /**
474
- * Format refresh token result
475
- * @param result Refresh token result
476
- * @returns Message
477
- */
478
- formatRefreshTokenResult(
479
- result: RefreshTokenResult<IActionResult<IUser>>
480
- ): string | undefined;
481
-
482
492
  /**
483
493
  * Format result text
484
494
  * @param result Action result
@@ -694,7 +704,7 @@ export interface IApp {
694
704
  * Refresh token
695
705
  * @param props Props
696
706
  */
697
- refreshToken(props?: RefreshTokenProps): Promise<boolean>;
707
+ refreshToken(props?: RefreshTokenProps): Promise<void>;
698
708
 
699
709
  /**
700
710
  * Setup Api error handler
@@ -734,17 +744,16 @@ export interface IApp {
734
744
 
735
745
  /**
736
746
  * Go to the login page
737
- * @param tryLogin Try to login again
738
- * @param removeUrl Remove current URL for reuse
747
+ * @param params Login parameters
739
748
  */
740
- toLoginPage(tryLogin?: boolean, removeUrl?: boolean): void;
749
+ toLoginPage(params?: AppLoginParams): void;
741
750
 
742
751
  /**
743
752
  * Try login, returning false means is loading
744
753
  * UI get involved while refreshToken not intended
745
- * @param showLoading Show loading bar or not
754
+ * @param params Login parameters
746
755
  */
747
- tryLogin(showLoading?: boolean): Promise<boolean>;
756
+ tryLogin(params?: AppLoginParams): Promise<void>;
748
757
 
749
758
  /**
750
759
  * Update API token and expires